<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 鼠标经过事件 </title>
<script type="text/javascript">
function message(){
var zhi;
document.getElementById("password").value= zhi;
if(zhi==0){
confirm("请输入密码后,再单击确定!"); }}
</script>
</head>
<body>
<form>
密码:<input name="password" type="password"value="0" >
<input name="确定" type="button" value="确定" onmouseover="message()"/>
</form>
</body>
</html>
赋予变量的格式应该是 变量 = 值,指的是将右边的值赋予左边的变量,位置不可调换;
且在body中应给容器定义id,否则将无法找到该id。
如想判定输入框内容为空,正确表达式为
if(zhi=="")或if(!zhi),if(zhi==0)表示的是判定zhi的值是否等于零。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 鼠标经过事件 </title>
<script type="text/javascript">
function message(){
var zhi;
zhi=document.getElementById("password").value;
if(zhi==""){
confirm("请输入密码后,再单击确定!"); }
}
</script>
</head>
<body>
<form>
密码:<input name="password" type="password"value="0" id="password">
<input name="确定" type="button" value="确定" onmouseover="message()"/>
</form>
</body>
</html>
var zhi= document.getElementById("password").value;