gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:21:21 24 4
gpt4 key购买 nike

嗨,我很熟悉使用 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>

关于javascript - 提交按钮的Onclick元素未调用JS函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28813572/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com