jquery表单submit()在使用即兴功能阻止正常提交后无法在回调函数内工作
我正在显示密码提示,而不是在用户单击表单的提交按钮时提交表单。我希望在用户单击提示的确定按钮时提交表单。我正在使用jquery即兴插件(同时使用版本3.1和4.0.1)。我很匆忙没有弄到我的代码有什么问题,或者我完全错过了什么。
I am displaying a password prompt instead of submitting the form when user clicks the submit button of a form. I want the form to submit when the user clicks the "Ok" button of the prompt. I am using jquery impromptu plugin (tried both with Version 3.1 and 4.0.1). I am in a hurry abd not getting what is wrong with my code or am I missing something completely.
这是我的代码 -
试用1
HTML部分
<form name="frmAddAdnetworkTemplate" id="frmAddAdnetworkTemplate" action="someAction">
...
...
<input id="submit" type="submit" name="submit" value="Submit" onclick="return promptPassword();" />
</form>
Javascript part
function promptPassword()
{
/*prepared passwordForm = some html; here */
$.prompt(passwordForm,{ buttons: { Ok:, Cancel: false , submit: }, callback: submitPasswordPrompt, focus: 1});
return false; //so as to not submit the form
}
function submitPasswordPrompt(value,m,form)
{
$("form#frmAddAdnetworkTemplate").submit(); //this does not work - no js error as well
}
但是,表格不提交。
试用版1.1
而不是在提交时调用submitPasswordPrompt,
Trial 1.1 Instead of calling submitPasswordPrompt on submit,
function promptPassword()
{
$.prompt(passwordForm,{ buttons:
{ Ok: $("#frmAddAdnetworkTemplate").submit(), //this too does not work
Cancel: false },
focus: 1
});
}
试用版1.2
我试过使用preventDefault() -
I tried with preventDefault() -
HTML部分
<input id="submit" type="submit" name="submit" value="Submit" onclick="promptPassword(event);"/>
Javascript part
function promptPassword(e)
{
e.preventDefault();
$.prompt(passwordForm,{ buttons: { Ok: true, Cancel: false }, submit: submitPasswordPrompt});
function submitPasswordPromptTest(e, value,m,form)
{
if(value)
{
$("#frmAddAdnetworkTemplate").submit(); //does not work
}
}
试用2
我还尝试通过绑定提交按钮上的click事件来调用文档文档.ready中的$ .prompt -
Trial 2 I also tried calling the $.prompt inside document document .ready, by binding with click event on the submit button -
HTML部分
<input id="submit" type="submit" name="submit" value="Submit" />
Javascript part
$("#submit").click(function(){
$.prompt(passwordForm,{ buttons: { Ok: $("#frmAddAdnetworkTemplate").submit(), Cancel: false }});
return false;
});
当我尝试$(#frmAddAdnetworkTemplate)。off('submit')时出现此错误。提交(); -
Got this error when I tried $("#frmAddAdnetworkTemplate").off('submit').submit(); -
e[h] is not a function
使用您的按钮ID提交
为我的Senario
for my senario
$.prompt(msg, {
buttons: btns,
submit: function (v) {
//this is simple pre submit validation, the submit function
//return true to proceed to the callback, or false to take
//no further action, the prompt will stay open.
},
callback: function (e, v, m, f) {
if (v) {
$("#MainContent_HiddenFieldIsContinueWithSave").val('1');
$("#MainContent_buttonSave").submit();
}
else { }
}
});