<title></title>
<style type="text/css">
input
{
color:#808080;
}
</style>
<script type="text/javascript">
function gel(id) { return document.getElementById(id); }
window.onload = function () {
var input = document.getElementsByTagName("input");
for (var i = 0; i < input.length; i++) {
input[i].onfocus = function () {
for (var j = 0; j < input.length; j++) {
input[j].style.backgroundColor = "#fff";
input[j].value="请输入正确的内容"
}
this.value = "";
this.style.backgroundColor = "yellow";
}
}
}
</script>
</head>
<body>
<table>
<tr>
<td id="td1"><input type="text" value="请输入正确的内容"/></td>
<td id="td1"><input type="text" value="请输入正确的内容"/></td>
<td id="td1"><input type="text" value="请输入正确的内容"/></td>
</tr>
</table>
</body>
转载于:https://www.cnblogs.com/Aamir-Ye/archive/2013/01/22/2872246.html
本文介绍了一种使用JavaScript实现的当输入框获得焦点时改变其背景颜色及清除默认提示文字的方法。通过为所有输入框添加事件监听器,在获取焦点时更新样式并清空预设值。
751

被折叠的 条评论
为什么被折叠?



