onblur和onfocus帮助- Javascript函数的替代品

onblur and onfocus Help - Javascript function alternative

本文关键字:函数 替代品 Javascript onfocus 帮助 onblur      更新时间:2023-09-26

我想知道如何用Javascript函数替换我的onblur/onfocus HTML代码,并对选择选项执行相同的技术。

代码示例:

<table>
<tr><td>
 <label  for="firstname">*Firstname:</label>
     <input type="text" name="udetail" id="firstname" value="(e.g. John)" 
     onblur="if(this.value == '') { this.style.color='#999'; this.value='(e.g. John)'} 
     {this.style.border='1px #bbb solid'}" onfocus="if (this.value == '(e.g. John)') 
     {this.style.color='#000'; this.value=''}" tabindex="1" />
 </td></tr>

  <tr><td>
     <label for="where">*How did you hear about us:</label>
 <select size="1" name="udetail" id="where" class="input"  
     tabindex="7" />
                                        <option value="blank">Select</option>                        
                                        <option value="ampdj">AMPdj</option>
                                        <option value="bing">Bing</option>
                                        <option value="google">Google</option>                  
                                        <option value="pastfunction">Past function</option>
                                        <option value="recomended">Recomended</option>
                                        <option value="yell">Yell</option>
                                        <option value="other">Other</option>                                            
  </select>                                                                                                                                    
  </td></tr>                      
  </table>

谢谢,斯科特

如果你没有严格要求在这些次要的ui元素中支持旧浏览器,我建议使用HTML5的输入标记占位符属性:

<input type="text" placeholder="(e.g. John)" />