giriş onfocus sorun

2 Cevap php

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 $_POST[l_username];
              else echo 'something';?>"   
     onfocus="if (this.value == 'something') {
 this.value='';this.style.color='black';}" />

onfocus burada çalışmıyor, ama değeri php komut sildiğinizde, bu işleri


<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

2 Cevap

<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';}" />

Eğer PHP komut önünde bir boşluk var. Bu javascript maç kaldırmaya çalışırsanız durum (if (this.value == 'something')

 " <?if ($_POST[l_username] != '') 
              echo $_POST[l_username];
              else echo 'something';?>" 

çünkü boşluk karakteri önce

Odak olay işleyicisi size defaultValue özelliğini kullanabilirsiniz, böylece iki kez "bir şey" dizesini tekrarlamak zorunda değilsiniz

onfocus="if(this.value === this.defaultValue){this.value='';this.style.backgroundColor='black';}"