input onfocus problem
it is the problem, i can't undertand anyway. i have the following simple script
    <input class="input"  type="text" name="l_username" style="color: #ccc;" 
     value= " <?if ($_POST[l_username] != '') 
              echo $_POS开发者_Go百科T[l_username];
              else echo 'something';?>"   
     onfocus="if (this.value == 'something') {
 this.value='';this.style.color='black';}" />
onfocus doesn't work here, but when i delete php script from value, it works
<input class="input"  type="text" name="l_username" style="color: #ccc;" 
         value= " something"   
         onfocus="if (this.value == 'something') {
     this.value='';this.style.color='black';}" />
it works fine. could you tell me why? thanks
<input class="input"  type="text" name="l_username" style="color: #ccc;" 
 value= " <?if ($_POST[l_username] != '') 
          echo $_POST[l_username];
          else echo 'something';?>"   
 onfocus="if (this.value == 'something') {
this.value='';this.style.color='black';}" />
you have a space in front of your PHP script. Try to remove it to match the javascript if case (if (this.value == 'something')
 " <?if ($_POST[l_username] != '') 
              echo $_POST[l_username];
              else echo 'something';?>" 
because of the space character before <?
In your focus event handler you could use the defaultValue property, so you don't have to repeat the "something" string twice
onfocus="if(this.value === this.defaultValue){this.value='';this.style.backgroundColor='black';}"
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论