如何实现当鼠标点击输入框时,输入框内的提示文字自动消失

如题所述

想要实现点击输入框消失,只需要给文本输入框加一点js效果即可,可以参考以下代码

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>txt</title>
<script type="text/javascript">
window.onload=function(){
var oIpt = document.getElementsByTagName('input')
oIpt[0].onclick=function(){
this.value = ""
}
}
</script>
</head>
<body>
<input type="text" value="点我消失!" name="">
</body>
</html>

以上代码实现的效果为,点击文本输入框之后设置input的value值为空。

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-03
第一种,文字是文本框的默认值:
<input type="text" class="textBox" value="222" />
$(".textBox").focus(function(){
$(".textBox").val("");

});
第二种,使用html的placeholder属性;鼠标点击时会自动隐藏:
<input type="text" class="textBox" placeholder="222" />
第三种,使用标签提示文字:
<p style="position:relative">
<input type="text" class="textBox" />
<span style="position:absolute; left:10px; top:0px;">提示文字</span>

</p>
$(".textBox").focus(function(){
$("span").hide();

});本回答被网友采纳
第2个回答  2016-09-30
Private Sub Text1_GotFocus()
If Text1.Text = "提示文字" Then Text1.Text = ""
End Sub

Private Sub Text1_LostFocus()
If Text1.Text = "" Then Text1.Text = "提示文字"
End Sub本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网