提交按钮的onclick元素不调用JS函数
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>
您好,我很熟悉 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>