[英]How to use the same jQuery UI dialog box?
我想使用jQuery UI对话框在不同的输入中显示错误。 我的问题是,我只想定义对话框的功能,但将其与包含id和特定错误消息的多个html关联。
我该怎么办?
此刻,我有这个:
// definition of the dialog, to do only once
$( "#dialog" ).dialog({
autoOpen: false,
show: {effect: 'fade', speed: 100},
hide: {effect: 'fade', speed: 100},
modal: true,
resizable: false,
title: "Incorrect value",
buttons: { Ok: function() { $(this).dialog( "close" ); }},
beforeClose: function() { $( "#time_at_address_years1" ).focus().val('') },
});
// the event, one per input
$( "#time_at_address_years1" ).blur(function() {
$( "#dialog1" ).dialog( "open" );
return false;
});
一条消息的HTML如下所示:
<div id="dialog">
<p>The error message here.</p>
</div>
只需在函数中扭曲对话框并将该函数传递给当前的jQuery选择器即可。
function my_dialog(selector, tofocus) {
$(selector).dialog({autoOpen:true, ...more options...});
}
比这样称呼它:
$( "#time_at_address_years1" ).blur(function() {
my_dialog('#dialog1', '#time_at_address_years1');
return false;
});
另外,您应该看看jQuery-Validator-Plugin http://docs.jquery.com/Plugins/Validation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.