[英]alert when the value of the button is submit
我有一個插入到我的網站的jQuery表單向導。 我要在這里做的是,當用戶到達表單的終點時,JavaScript彈出警報向他顯示。 我在頁面頂部<head>..some code</head>
嘗試了非常簡單的JavaScript代碼
function alertme() {
if (this.value = "Submit") {
alert("welcome");
}
else {
return false;
}
}
事件OnClick()
發生時我試圖運行此功能的HTML按鈕
<input class="navigation_button" id="next" value="Next" type="submit" onclick="alertme();" />
如您所見,現在的值是Next
,這里的問題是我的JavaScript函數忽略該值,並在表單步驟中單擊按鈕時彈出警報,我該如何解決此問題?
看起來您的問題出在第二行代碼中。
您需要一個雙等於。 this.value == "Submit"
...您還需要在函數中傳遞“ this”。 完整答案:
<input class="navigation_button" id="next" value="Next" type="submit" onclick="alertme(this);" />
function alertme(e) {
if (e.value == "Submit") {
alert("welcome");
}
else {
return false;
}
}
function alertme() {
if (document.getElementById('next').value == "Submit") {
alert("welcome");
}
else {
return false;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.