判斷輸入是否為空,但運(yùn)行不管輸入是否為空,都會(huì)執(zhí)行?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 鼠標(biāo)經(jīng)過事件 </title>
<script type="text/javascript">
? ? function message(){
? ? ? ? var txt=document.getElementById("num").innerHTML;
? ? ? ??
? ? ? ? if(!txt){
? ? ? confirm("請(qǐng)輸入密碼后,再單擊確定!");}
? ? ? }
</script>
</head>
<body>
<form>
密碼:<input name="password" id="num" type="password" >
<input name="確定" type="button" value="確定" onmouseover="message()"/>
</form>
</body>
</html>
2022-03-29
養(yǎng)成轉(zhuǎn)義好習(xí)慣,或者加r#39;xxx#39;
tmyxicxzmbbdgkvzfukdbaogllobiftyfdexofxsahfmmqlnzbszlragczwhoqzojrlwdajhafrpzloiuxwvsxyyonlncdtwkuyodbmzyzvpdttiasoexkmhemlafhowpyocmdpbowjudooqa
2018-09-29
<!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="請(qǐng)輸入密碼后,再單擊確定!";
}
else{
y.innerHTML="提交成功!";
}
}
</script>
</head>
<body>
? 請(qǐng)輸入密碼:<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;? ?指的是獲取文本框的內(nèi)容;
document.getElementById("num").innerHTML;? 指的是獲取文本的內(nèi)容;
2018-09-22
? ?應(yīng)該是var txt=document.getElementById("num").value;
判斷的值有問題