如何使jQuery中的对话框仅在按下按钮后显示?
此代码来自jQuery站点上的模态确认演示如何使jQuery中的对话框仅在按下按钮后显示?,jquery,dialog,Jquery,Dialog,此代码来自jQuery站点上的模态确认演示 <script type="text/javascript"> $(function() { $("#dialog").dialog({ bgiframe: true, resizable: false, height:140, modal: true, overlay: { backgroundColor: '#000',
<script type="text/javascript">
$(function() {
$("#dialog").dialog({
bgiframe: true,
resizable: false,
height:140,
modal: true,
overlay: {
backgroundColor: '#000',
opacity: 0.5
},
buttons: {
'Yes': function() {
$(this).dialog('close');
},
'No': function() {
$(this).dialog('close');
}
}
});
});
</script>
<div class="demo">
<div id="dialog" title="Empty the recycle bin?">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
<!-- Sample page content to illustrate the layering of the dialog -->
<div class="hiddenInViewSource" style="padding:20px;">
<p>Sed vel diam id libero <a href="http://example.com">rutrum convallis</a>. Donec aliquet leo vel magna. Phasellus rhoncus faucibus ante. Etiam bibendum, enim faucibus aliquet rhoncus, arcu felis ultricies neque, sit amet auctor elit eros a lectus.</p>
<form>
<input value="text input" /><br />
<input type="checkbox" />checkbox<br />
<input type="radio" />radio<br />
<select>
<option>select</option>
</select><br /><br />
<textarea>textarea</textarea><br />
</form>
</div><!-- End sample page content -->
</div><!-- End demo -->
<div class="demo-description">
<p>Confirm an action that may be destructive or important. Set the <code>modal</code> option to true, and specify primary and secondary user actions with the <code>buttons</code> option.</p>
</div><!-- End demo-description -->
谁能告诉我,只有在我按下按钮后,如何才能制作这个节目?现在,它在加载后立即自动显示在页面中。将按钮添加到页面中,并将代码添加到按钮的单击事件中
<script type="text/javascript">
$(function() {
$("#button").click(function(){
$("#dialog").dialog({
bgiframe: true,
resizable: false,
height:140,
modal: true,
overlay: {
backgroundColor: '#000',
opacity: 0.5
},
buttons: {
'Yes': function() {
$(this).dialog('close');
},
'No': function() {
$(this).dialog('close');
}
}
});
});
});
</script>
$(函数(){
$(“#按钮”)。单击(函数(){
$(“#对话框”)。对话框({
bgiframe:是的,
可调整大小:false,
身高:140,
莫代尔:是的,
覆盖:{
背景颜色:“#000”,
不透明度:0.5
},
按钮:{
“是”:函数(){
$(this.dialog('close');
},
“否”:函数(){
$(this.dialog('close');
}
}
});
});
});
和HTML格式
<input type='button' value="click" id="button"/>
这将打开您定义的对话框-附加对话框打开功能以单击按钮的事件
哦-并在对话框设置属性:)上设置
autoOpen:false
对错,下面是我使用的通用警报样式对话框的示例:
设置对话框(在“文档准备就绪”中):
并打开对话框(在某些事件之后):
我只慢了几秒钟+我的答案被删除了。
$("#btnTest").click(function() {
$('#dialog').dialog('open');
return false;
})
$("#generic-dialog").dialog({
autoOpen: false,
buttons: {
Ok: function() {
$(this).dialog("close");
}
}
});
$("#generic-dialog")
.text("Status updated successfully.")
.dialog("option", "title", "Your Status").dialog("open");