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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2020-05-13 我要评论
复制代码 代码如下:

<!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>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们