0

jQuery UI ダイアログを使用して、さまざまな入力のエラーを表示したいと考えています。私の問題は、ダイアログ ボックスの機能を 1 つだけ定義し、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;
});

1 つのメッセージの HTML は次のようになります。

<div id="dialog">
<p>The error message here.</p>
</div>
4

1 に答える 1

0

ダイアログを関数でワープし、その関数に現在の 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もご覧ください。

于 2012-08-08T09:12:46.567 に答える