你如何关闭一个 jQuery Simplemodal?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/935573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you close a jQuery Simplemodal?
提问by pupeno
I want to close a Simplemodal window from a JavaScript function that gets called automatically after a form is submitted and the results recived (AJAX), using ASP.Net MVC. How do I close a jQuery Simplemodal?
我想从使用 ASP.Net MVC 提交表单并收到结果 (AJAX) 后自动调用的 JavaScript 函数关闭 Simplemodal 窗口。如何关闭 jQuery Simplemodal?
I've opened it this way:
我是这样打开的:
$("#popup").modal()
回答by Eric Martin
You have 2 options:
您有 2 个选择:
1) Put the close class (simplemodal-close) on an element in your modal data and SimpleModal will automatically bind the close function to the click event on that element.
1)将关闭类(simplemodal-close)放在模态数据中的元素上,SimpleModal 将自动将关闭函数绑定到该元素上的点击事件。
Taking the example above, you'd want:
以上面的例子为例,你会想要:
<div id="foo" style="display:none">
<p>Form HTML</p>
<span class="simplemodal-close">Close</span>
</div>
2) When you want to close the dialog programatically, call:
2)当你想以编程方式关闭对话框时,调用:
$.modal.close();
HTH!
哼!
-Eric (SimpleModal author)
-Eric(SimpleModal 作者)
回答by gradbot
Just call close.
就打电话关闭。
$("#popup").close();
If you're doing it for an ajax completion you need to add a callback. You may want to check for failure.
如果你是为了 ajax 完成而做的,你需要添加一个回调。您可能想要检查是否失败。
var foo = $("#popup").modal();
$.ajax({url:url, success:function(){
foo.close();
}});
回答by milesholt
If none of the above solutions work, you can also try to trigger the click event of the close button (so long as it is placed inside the popup element).
如果以上解决方案都不起作用,您也可以尝试触发关闭按钮的点击事件(只要它放在弹出元素内)。
$( ".simplemodal-close" ).trigger( "click" );
or failing that, with Javascript.
或者失败了,使用 Javascript。
document.getElementById('closeModalButton').click();
回答by dhaniBinZain
$.modal.close();
or you can use following command
或者您可以使用以下命令
setTimeout('goto_previous_page()', 1000);