简体   繁体   English

提交按钮的Onclick元素未调用JS函数

[英]Onclick element of Submit Button Not Calling JS Function

Hi I'm familiar with using onsubmit and onclick as I have used them before, but for some reason it refuses to work this time around. 嗨,我熟悉使用onsubmit和onclick,就像我以前使用过的一样,但是由于某种原因,它这次拒绝工作。 I've looked at my old code and tried everything to make it exactly the same yet it still will not run. 我查看了我的旧代码,并尝试了所有使其完全相同的代码,但仍然无法运行。

 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> 

Man, it's document.getElementById 伙计,它是document.getElementById
by the way, let's clean that code: 顺便说一下,让我们清理一下代码:

HTML: 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: Javascript:

function verifypass() {
    var password = "Testpass";
    var string = document.getElementById("verifybadge").value;
    if(string !== password) {
        alert("Wrong password!");
        window.location="about:blank";
    }
}

This code works (notice the .value as suggested by @John) 此代码有效(请注意@John建议的.value)


Under here a snippet: 下面是一个片段:

 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM