大佬教程收集整理的这篇文章主要介绍了jQuery UI-在外部单击时关闭对话框,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
查看jQuery Outside Events插件
让您做:
$fIEld_hint.bind('clickoutsIDe',function(){
$fIEld_hint.dialog('close');
});
我有一个jQuery UI对话框,当单击特定元素时会显示该对话框。如果在那些触发元素或对话框本身之外的任何地方都单击了鼠标,我想关闭对话框。
这是打开对话框的代码:
$(document).ready(function() {
var $field_hint = $('<div></div>')
.dialog({
autoOpen: false,minHeight: 50,resizable: false,width: 375
});
$('.hint').click(function() {
var $hint = $(this);
$field_hint.html($hint.html());
$field_hint.dialog('option','position',[162,$hint.offset().top + 25]);
$field_hint.dialog('option','title',$hint.siblings('label').html());
$field_hint.dialog('open');
});
/*$(document).click(function() {
$field_hint.dialog('close');
});*/
});
如果我取消最后一部分的注释,该对话框将永远不会打开。我认为这是因为打开对话框的同一点击再次将其关闭。
最后的工作代码
注意:这是使用 jQuery外部事件插件
$(document).ready(function() {
// dialog element to .hint
var $field_hint = $('<div></div>')
.dialog({
autoOpen: false,minHeight: 0,width: 376
})
.bind('clickoutside',function(E) {
$target = $(e.target);
if (!$target.filter('.hint').length
&& !$target.filter('.hintclickicon').length) {
$field_hint.dialog('close');
}
});
// attach dialog element to .hint elements
$('.hint').click(function() {
var $hint = $(this);
$field_hint.html('<div style="max-height: 300px;">' + $hint.html() + '</div>');
$field_hint.dialog('option',[$hint.offset().left - 384,$hint.offset().top + 24 - $(document).scrollTop()]);
$field_hint.dialog('option',$hint.siblings('label').html());
$field_hint.dialog('open');
});
// trigger .hint dialog with an anchor tag referencing the form element
$('.hintclickicon').click(function(E) {
e.preventDefault();
$($(this).get(0).hash + ' .hint').trigger('click');
});
});
以上是大佬教程为你收集整理的jQuery UI-在外部单击时关闭对话框全部内容,希望文章能够帮你解决jQuery UI-在外部单击时关闭对话框所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。