麻煩能幫忙看下這段代碼是哪里出錯了嗎,測驗一直沒有反應,謝謝
<head>
<script type="text/javascript">
function check(){
if(document.getElementById("name").value == ""){
alert("請完整輸入!");
return false;
}else{
return true
}
}
</script>
</head>
<body>
<form action="test.html" method="post" onsubmit="return check()">
<input type="text" id="name"/>
<input type="submit" >
</form>
</body>
uj5u.com熱心網友回復:
<html>我這邊測驗是好的,你網頁是不是屏蔽JS了
<head>
<script type="text/javascript">
function check(){
if(document.getElementById("name").value == ""){
alert("請完整輸入!");
return false;
}else{
return true
}
}
</script>
</head>
<body>
<form action="test.html" method="post" onsubmit="return check()">
<input type="text" id="name"/>
<input type="submit" >
</form>
</body>
</html>
uj5u.com熱心網友回復:
我發現是我前面多了個 window.onload =function(){...} ,麻煩咨詢一下為什么加了就不對呢<head>
<script type="text/javascript">
window.onload =function(){
function check(){
if(document.getElementById("name").value == ""){
alert("請完整輸入!");
return false;
}else{
return true
}
}
}
</script>
</head>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/268484.html
標籤:JavaScript
上一篇:關于代碼中的理解疑惑
