jQuery Alert -jAlert OK 点击
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10088615/
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
jQuery Alert -jAlert OK click
提问by Neena
On click of OK in jAlert nothing is triggered, even the dialog box doesn't close:
在 jAlert 中单击 OK 没有触发任何事件,即使对话框没有关闭:
$(document).ready(function () {
$("#confirm_button").click(function () {
jAlert("Submitted", "Approval", function () {
//My code goes in here
});
});
});
I need to get the event on OK click, please help me out in this!
我需要点击 OK 获得事件,请帮我解决这个问题!
The HTML
HTML
<html>
<head>
<title>Demo</title>
<script src="jquery.js" charset="utf-8" type="text/javascript"></script>
<script src="jquery.alerts.js" charset="utf-8" type="text/javascript"></script>
<link href="jquery.alerts.css" charset="utf-8" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript">
$(document).ready(function () {
$("#confirm_button").click(function () {
jAlert("Submitted", "Approval", function () {
//
});
});
});
</script>
</head>
<body>
<form runat="server">
<asp:Button ID="btnAlert" runat="server" Text="Click"/>
</form>
<input id="confirm_button" type="button" value="Show Confirm" />
</body>
</html>
回答by dxh
回答by Manse
I had to make a small change to your code
我不得不对你的代码做一个小改动
jAlert
to
到
$.jAlert
回答by André Silva
Is the selector named confirm_button an input? if it is, try doing this :
名为 confirm_button 的选择器是输入吗?如果是,请尝试这样做:
$("input[name=confirm_button").click(function () {
If the selector is named after a class like :
如果选择器以如下类命名:
<a class="confirm_button"></a>
Then do this :
然后这样做:
$(".confirm_button").click(function() {
回答by Guy Nakash
From my understanding the jAlert popup's OK button is "#popup_ok" meaning that's the unique ID of the instance. So you have to bind an event to this button AFTER the jAlert function is fired. Here I've wrapped the jAlert call inside of another function which does so:
根据我的理解,jAlert 弹出窗口的 OK 按钮是“#popup_ok”,意思是实例的唯一 ID。因此,您必须在触发 jAlert 函数后将事件绑定到此按钮。在这里,我将 jAlert 调用包装在另一个函数中:
function showAlert(msg, title) {
jAlert(msg, title);
$("#popup_ok").click(
function () {
// Do something after the OK button is clicked...
});
}
and now you call the "mother" function:
现在你调用“mother”函数:
showAlert("Click OK if you're OK...", "Hey how are you doing?");