[英]How to use the same jQuery UI dialog box?
I want to use a jQuery UI dialog to display the errors in the different inputs. 我想使用jQuery UI对话框在不同的输入中显示错误。 My problem is that I would like to define the feature of dialog box only one but associate it with several html containing an id and a specific error message.
我的问题是,我只想定义对话框的功能,但将其与包含id和特定错误消息的多个html关联。
How could I do that? 我该怎么办?
At the moment, I have this: 此刻,我有这个:
// 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;
});
And the HTML of one message is like this: 一条消息的HTML如下所示:
<div id="dialog">
<p>The error message here.</p>
</div>
Just warp the dialog in a function and pass that function the current jQuery-selector. 只需在函数中扭曲对话框并将该函数传递给当前的jQuery选择器即可。
function my_dialog(selector, tofocus) {
$(selector).dialog({autoOpen:true, ...more options...});
}
Than call it like this: 比这样称呼它:
$( "#time_at_address_years1" ).blur(function() {
my_dialog('#dialog1', '#time_at_address_years1');
return false;
});
Also, you should have a look at the jQuery-Validator-Plugin http://docs.jquery.com/Plugins/Validation 另外,您应该看看jQuery-Validator-Plugin http://docs.jquery.com/Plugins/Validation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.