给出示例:
<html><head>
<meta http-equiv="content-type" content="text/htmlcharset=GBK">
<script type="text/javascript">
function clearVal() {
// 获取文本框对象
var el = document.getElementById('num')
if (el) {
// 将文本框对象值清空
el.value = ''
}
}
</script>
</head>
<body>
<form action="Untitled-3.html" name="form" method="post">
<div>Tem<br><input type="text" name="num" id="num" value='7' /></div>
<div>
<input type="button" value="按钮" onclick="clearVal()"/>
</div>
</form>
</body>
</html>
<!DOCTYPE html><html>
<head>
<meta charset="GB2312">
<title></title>
<script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
</head>
<body>
<input id="text" type="text" />
<span id="ccc" style="display: none">X</span>
<script type="text/javascript">
var text = $('#text')
var ccc = $('#ccc')
text.focus(function(){
ccc.show()//文本框获得据点显示X
})
ccc.click(function(){
text.val('')//清空
ccc.hide()//隐藏x
})
</script>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)