精慕门9295324
2018-09-22 11:06
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 鼠标经过事件 </title>
<script type="text/javascript">
function message(){
var txt=document.getElementById("num").innerHTML;
if(!txt){
confirm("请输入密码后,再单击确定!");}
}
</script>
</head>
<body>
<form>
密码:<input name="password" id="num" type="password" >
<input name="确定" type="button" value="确定" onmouseover="message()"/>
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>判断输入框是否为空</title>
<script>
function message(){
var x=document.getElementById("num").value;
var y=document.getElementById("tip");
if(!x){
y.innerHTML="请输入密码后,再单击确定!";
}
else{
y.innerHTML="提交成功!";
}
}
</script>
</head>
<body>
请输入密码:<input type="password" name="password" id="num"><br>
<div id="tip"></div>
<input type="button" value="确定" id="btn" onMouseOver="message()">
</body>
</html>
ps:
document.getElementById("num").value; 指的是获取文本框的内容;
document.getElementById("num").innerHTML; 指的是获取文本的内容;
应该是var txt=document.getElementById("num").value;
判断的值有问题
JavaScript进阶篇
468194 学习 · 21891 问题
相似问题