想问一下var pwd放在外面不是全局变量吗?为什么要放在函数里面才行
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 鼠标点击事件 </title>
<script type="text/javascript">
var pwd=document.getElementById("password").value;
function message(){
if(pwd==""){
confirm("请输入密码后,再单击确定!");
}else{
alert("登陆成功");
}
}
</script>
</head>
<body>
<form>
密码:<input name="password" type="password" id="password">
<input name="确定" type="button" value="确定" onclick="message()"/>
</form>
</body>
</html>