jQuery 对话框打开时触发事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18992081/
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
Trigger event on dialog box open
提问by user2583714
My dialog box is defined under the div
我的对话框是在div下定义的
#dialogbox
When the dialog box opens i want to trigger an event such that it alerts open. The code im using is:
当对话框打开时,我想触发一个事件,以便它打开警报。我使用的代码是:
$("#dialogbox").dialog({open: function(){
alert("OPEN");
}
});
But this doesnt seem to trigger when dialog box is opened Please help
但这似乎在打开对话框时不会触发 请帮忙
回答by Donovan Charpin
You can use this :
你可以使用这个:
$( ".selector" ).dialog({
open: function( event, ui ) {}
});
or the event listener .on
或事件侦听器 .on
$( ".selector" ).on( "dialogopen", function( event, ui ) {} );
More information in this page :
此页面中的更多信息:
回答by cssyphus
Try this:
尝试这个:
HTML:
HTML:
<div id="dialogbox"></div>
<input id="mybutt" type="button" value="Click Me">
Javascript/jQuery:
Javascript/jQuery:
$("#dialogbox").dialog({
autoOpen:false,
modal:true,
title: "Use of Open event",
width:300,
open: function( event, ui ) {
alert('hello');
}
});
$('#mybutt').click(function() {
$('#dialogbox').html('<h2>Watch this</h2>An alert box should have opened');
$('#dialogbox').dialog('open');
});
回答by sher bahadur
It will display alert after clicking on the OK button.
单击“确定”按钮后,它将显示警报。
$( "#WaitingDialog").html("Message you want to display").dialog({
modal: true,
buttons: {
Ok: function() {
alert("hello");
}
}});
It will display alert after opening the modal
打开模态后它会显示警报
$( "#WaitingDialog").html("Message you want to display").dialog({
modal: true,
buttons: {
open: function( event, ui ) {
alert('hello');
}
}});
回答by prince jose
You can also use the focusevent Click here for documentation
您还可以使用焦点事件 单击此处获取文档