if else if mousedown事件的声明
我的目标是为每个单击的项目显示不同的对话框。 我目前有一个设置,并认为我可以添加一个if语句。 如果在div_a,dialog_a上mousedown,否则如果在div_b,dialog_b等上mousedown …我是编码的新手并且无法想象这个。
这是我的对话框代码:
$(document).ready(function(){ $("#questiona").mousedown(function(){ $("#dialoga").dialog(); }); });
由于您不熟悉编码,我建议使用jQuery团队的jQueryUI库 – 其中包含.dialog()
function(他们称之为“小部件”)。 以下是它的工作原理:
(1)在标记中包含jQuery 和 jQueryUI库。 请注意,您还必须为jQueryUI包含适当的CSS主题库(或者对话框将不可见):
(2)在HTML中创建一个空div,并将其初始化为对话框:
HTML:
jQuery的:
$('#myDlg').dialog({ autoOpen:false, modal:true, width: 500, height: 'auto' });
(3)然后,当您准备好显示对话框时,在打开对话框之前将新数据插入myDlg
div:
$('#myDlg').html('This will display in the dialog'); $('#myDlg').dialog('open');
以上允许您更改对话框的内容,并每次使用重新相同的对话框DIV。
以下是工作示例的样子:
jsFiddle演示
HTML:
What is 2 + 2? 4 What is the 12th Imam? The totally wacky reason why Iran wants a nuclear bomb.
jQuery的:
var que,ans; $('#myDlg').dialog({ autoOpen:false, modal:true, width: 500, height: 'auto', buttons: { "See Answer": function(){ $('#myDlg').html(ans); $('.ui-dialog-buttonset').next('button').hide(); }, "Close": function(){ $('#myDlg').html('').dialog('close'); } } }); $('.allques').click(function(){ que = $(this).find('.question').html(); ans = $(this).find('.answer').html(); $('#myDlg').html(que).dialog('open'); });
资源:
如何使用PopUp插件
http://blog.nemikor.com/2009/04/08/basic-usage-of-the-jquery-ui-dialog/
jQuery UI对话框 – 关闭后无法打开
动态更改jQueryUI对话框按钮
jQuery UI对话框 – 关闭事件的问题