Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: помогите упростить код
Форумы портала PHP.SU » Клиентская разработка » JavaScript & VBScript » помогите упростить код

Страниц (1): [1]
 

1. -=1100=- - 04 Июля, 2008 - 19:47:57 - перейти к сообщению
Всем привет!
Такое дело...

Форма
CODE (text):
скопировать код в буфер обмена
  1.  <form name="r1" action="registr.php" method="POST">
  2.                    <input class="input_registr" type="text" name="fname"  value="Фамилия" tabindex="1" onFocus="reg11()" onBlur="reg12()">
  3.                    <input class="input_registr" type="text" name="iname" value="Имя" tabindex="2" onFocus="reg21()" onBlur="reg22()">
  4.                    <input class="input_registr" type="text" name="oname" value="Отчество" tabindex="3" onFocus="reg31()" onBlur="reg32()">
  5.                  </form>


JS
CODE (text):
скопировать код в буфер обмена
  1. <script type="text/javascript">
  2.   function reg11(){
  3.      r1.fname.style.color="black";
  4.          r1.fname.style.fontSize="12pt";
  5.          r1.fname.value='';
  6.          r1.fname.style.borderStyle="double";
  7.          r1.fname.style.borderWidth="3";
  8.          r1.fname.style.backgroundColor="white";
  9.          r1.fname.style.fontStyle="normal";
  10.          r1.fname.style.fontWeight="bold";
  11.          }
  12.   function reg12(){
  13.      r1.fname.style.borderStyle="solid";
  14.          r1.fname.style.borderWidth="1";
  15.          r1.fname.style.color="6E6E6E";
  16.          r1.fname.style.backgroundColor="silver";
  17.          r1.fname.style.color="black";
  18.          
  19.          }
  20.    function reg21(){
  21.          r1.iname.style.fontSize="12pt";
  22.          r1.iname.value='';
  23.          r1.iname.style.borderStyle="double";
  24.          r1.iname.style.borderWidth="3";
  25.          r1.iname.style.backgroundColor="white";
  26.          r1.iname.style.fontStyle="normal";
  27.          r1.iname.style.fontWeight="bold";
  28.          r1.iname.style.color="black";
  29.          }
  30.   function reg22(){
  31.          r1.iname.style.borderStyle="solid";
  32.          r1.iname.style.borderWidth="1";
  33.          r1.iname.style.color="6E6E6E";
  34.          r1.iname.style.backgroundColor="silver";
  35.          r1.iname.style.color="black";
  36.          }
  37.   function reg31(){
  38.          r1.oname.style.fontSize="12pt";
  39.          r1.oname.value='';
  40.          r1.oname.style.borderStyle="double";
  41.          r1.oname.style.borderWidth="3";
  42.          r1.oname.style.backgroundColor="white";
  43.          r1.oname.style.fontStyle="normal";
  44.          r1.oname.style.fontWeight="bold";
  45.      r1.oname.style.color="black";
  46.          }
  47.   function reg32(){
  48.          r1.oname.style.color="black";
  49.          r1.oname.style.borderStyle="solid";
  50.          r1.oname.style.borderWidth="1";
  51.          r1.oname.style.color="6E6E6E";
  52.          r1.oname.style.backgroundColor="silver";
  53.          r1.oname.style.color="black";   }
  54. </script>


Тут всего 3 поля ввода текста, а мне надо шут 20 их. В таком случаи скрипт получится ... А?!

Можно ли как нибудь его уменьшить? Если да, то как?
(Добавление)
А, все! уже не надо. Сам справился.
Я вот как сделал

CODE (text):
скопировать код в буфер обмена
  1.  <form name="r1" action="registr.php" method="POST">
  2.                    <input class="input_registr" type="text" name="fname"  value="Фамилия" tabindex="1" onFocus="reg1(this)" onBlur="reg2(this)">
  3.                    <input class="input_registr" type="text" name="iname" value="Имя" tabindex="2" onFocus="reg1(this)" onBlur="reg2(this)">
  4.                    <input class="input_registr" type="text" name="oname" value="Отчество" tabindex="3" onFocus="reg1(this)" onBlur="reg2(this)">
  5.                  </form>


CODE (text):
скопировать код в буфер обмена
  1. <script type="text/javascript">
  2.   function reg1(obj){
  3.      obj.style.color="black";
  4.          obj.style.fontSize="12pt";
  5.          obj.value='';
  6.          obj.style.borderStyle="double";
  7.          obj.style.borderWidth="3";
  8.          obj.style.backgroundColor="white";
  9.          obj.style.fontStyle="normal";
  10.          obj.style.fontWeight="bold";
  11.          }
  12.   function reg2(obj){
  13.      obj.style.borderStyle="solid";
  14.          obj.style.borderWidth="1";
  15.          obj.style.color="6E6E6E";
  16.          obj.style.backgroundColor="silver";
  17.          obj.style.color="black";}
  18. </script>
2. kamikadze - 05 Июля, 2008 - 00:59:49 - перейти к сообщению
Хм, использоват стили, которые яваскриптом и подменивать

 

Powered by ExBB FM 1.0 RC1