[英]Onclick element of Submit Button Not Calling JS Function
嗨,我熟悉使用onsubmit和onclick,就像我以前使用過的一樣,但是由於某種原因,它這次拒絕工作。 我查看了我的舊代碼,並嘗試了所有使其完全相同的代碼,但仍然無法運行。
function verifypass() { var password = "Testpass"; var string = document.getElementByID("verifybadge"); if(string!=password) { alert("Wrong password!"); window.location="about:blank"; } }
<form name="receivingform" method="post"> </br></br> <b>Please Enter Password to Verify Closure of Ticket: </b> </br> <input type="text" size="15" maxlength="20" id="verifybadge"> </br> <input class="button_text" type="submit" value="Delete Closed Rows" onclick="verifypass();"> </form>
伙計,它是document.getElementById
順便說一下,讓我們清理一下代碼:
HTML:
<form name="receivingform" method="post">
<br/><br/>
<b>Please Enter Password to Verify Closure of Ticket: </b> <br/>
<input type="text" size="15" maxlength="20" id="verifybadge" /> <br/>
<input class="button_text" type="submit" value="Delete Closed Rows" onclick="verifypass()" />
</form>
Javascript:
function verifypass() {
var password = "Testpass";
var string = document.getElementById("verifybadge").value;
if(string !== password) {
alert("Wrong password!");
window.location="about:blank";
}
}
此代碼有效(請注意@John建議的.value)
function verifypass() { var password = "Testpass"; var string = document.getElementById("verifybadge").value; if(string !== password) { alert("Wrong password!"); //window.location="about:blank"; } else alert("yay"); }
<form name="receivingform" method="post"> <br/><br/> <b>Please Enter Password to Verify Closure of Ticket: </b> <br/> <input type="text" size="15" maxlength="20" id="verifybadge" /> <br/> <input class="button_text" type="button" value="Delete Closed Rows" onclick="verifypass()" /> </form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.