亲宝软件园·资讯

展开

当某个文本框成为焦点时即清除文本框内容

人气:0
复制代码 代码如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>成为焦点时清除文本框内容</title>
<script>
window.onload = initAll;

function initAll(){
var clearText = document.getElementsByTagName("input");
for (var i=0; i<clearText.length; i++){
clearText[i].onfocus = function ( ){
this.value = "";
}
}
}
</script>
</head>

<body>
文本框一:<input type="text" name="text" id="clearText1" value="清除文本框一的内容"/><br/>
文本框二:<input type="text" name="text" id="clearText2" value="清除文本框二的内容"/><br/>
文本框三:<input type="text" name="text" id="clearText3" value="清除文本框三的内容"/>
</body>
</html>

加载全部内容

相关教程
猜你喜欢
用户评论