簡體   English   中英

如何使用相同的jQuery UI對話框?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM