<div class="codetitle"> <span><a style="CURSOR: pointer" data="4815" class="copybut" id="copybut4815" onclick="doCopy('code4815')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code4815"> <br> <br> <br> <br><meta charset="utf-8"> <br><title>成为焦点时清除文本框内容</title> <br><script> <BR>window.onload = initAll; <br><br>function initAll(){ <BR>var clearText = document.getElementsByTagName("input"); <BR>for (var i=0; i<clearText.length; i++){ <BR>clearText[i].onfocus = function ( ){ <BR>this.value = ""; <BR>} <BR>} <BR>} <BR></script> <br> <br><br> <br>文本框一:<input type="text" name="text" id="clearText1" value="清除文本框一的内容"><br> <br>文本框二:<input type="text" name="text" id="clearText2" value="清除文本框二的内容"><br> <br>文本框三:<input type="text" name="text" id="clearText3" value="清除文本框三的内容"> <br> <br> <br> </div>