[英]Calling first button on confirm of second button in javascript isn't working
I have two buttons in my html page and when someone clicks Generate button I want to save my document (the same thing save button is doing) if ok is clicked otherwise I do not want to do anything. 我的html页面中有两个按钮,当有人单击“生成”按钮时,如果单击“确定”,我想保存我的文档(保存按钮正在做同样的事情),否则我什么也不想做。
Js code $("#save-application").trigger("click"); js代码$(“#save-application”)。trigger(“ click”);
I also tried to use 我也尝试使用
document.getElementById('save-application').click();
and 和
$('#save-application').click();
But it isnt working.So basically I want to call my save button.Any suggestions on this? 但是它不起作用,所以基本上我想调用我的保存按钮,对此有任何建议吗?
I did tried 我确实尝试过
if (check == true) {
$("#form").submit();
return true;
}
else {
return false;
}
but form doesn't get saved 但是表格没有保存
I think you missed #
while querying by id $("#save-application").click();
我想您在通过ID
$("#save-application").click();
查询时错过了#
$("#save-application").click();
. 。
Instead of using trigger , you can create separate function for save functionality, html code : 除了使用trigger之外,您还可以为保存功能创建单独的函数html代码:
<input type="submit" value="Save" id="save-application" onclick="saveApplication();"/>
js code : js代码:
function saveApplication(){
//logic here
}
and then call saveApplication() instead of $("save-application").trigger("click"); 然后调用saveApplication()而不是$(“ save-application”)。trigger(“ click”);
So I'd do something like this on your input 所以我会在你的输入上做这样的事情
<input id="save-application" type="submit" value="Save" onclick="saveApplication()"/>
Then modify your javascript to something like this: 然后将您的javascript修改为如下所示:
function saveApplication() {
if (isChanged == true ) {
var check = confirm("Would you like to to save your changes and have a document generated?");
if (check == true) {
$("#save-application").trigger("click");
return true;
}
else { return false; }
} else {
return undefined;
}
}
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.