0

内にいくつかのコンテンツfunctionを表示するための を定義しました:htmljqueryui dilaog

function ui_window(title, dialogWidth, content,buttons,className)
{
  $('<div id="window">').html(content).
  dialog({
      title: title,
      show: 'drop',
      hide: 'drop',
      width: dialogWidth,
      buttons: buttons,
      close: function (ev, ui) { $(this).remove(); },
      position: { my: 'center', at: 'center', of: window }
}
   ).addClass(className);
  return false;
}

functionそして、上記を呼び出す別の JavaScriptを次に示しfunctionます。

function checkForValidCommand()
{
var content = getInnerHTML("#checkForValidCommand");
var myFunc = function ()
{
    var pensionerID = $('#txtID').val();
        alert(pensionerID);
        $(this).dialog('destroy');
    }
    else
        $('#txtID').focus();
}
var buttons = [{ text: 'OK', click: myFunc}];
ui_window("Pensioner", 410, content, buttons);

}

checkForValidCommand初めて" " を呼び出し、inputavalueのみを呼び出して [ textboxOK] を押すと、 の値でアラートが表示されますtextbox。そして、再度 を呼び出して、にfunction何も入力せずに [OK] を押す と、古い. 私のコードの問題は何ですか?textboxalertvalue

編集:見たい場合のhtmlコンテンツは次のとおりです。

<table>
  <tr>
    <td align="right">
       <label>
           Insert the pensioiner's ID:
       </label>
    </td>
    <td>
     <input id="txtID" type="text" onkeydown="return onlyNumbers(event);" maxlength="8"/>
    </td>
  </tr>
</table>
4

1 に答える 1

2

OK.私はこの質問に自分で答えることができてとてもうれしく思います. したがって、問題は、テキストボックスを含む新しいjqueryダイアログを開くたびに、テキストボックスの値が最初のダイアログの値になることでした。どういうわけか、jquery は古い値を保持していました。置いても$(this).dialog('destroy');問題は解決しませんでした(このコマンドでダイアログが完全に削除されない理由は別の話です)。それから私は突然次の動作原理を思い出しました$('#id')

It goes and selects the first matching element with the specified id.

これは必要な手がかりでした。以前のダイアログが本文から削除されていないことは確かでした。遺体を確認したところ、私が正しかったことがわかりました。すべてのダイアログは本文にありました。div を完全に削除するために多くの方法を試しましたが、機能しているとわかった唯一の方法で停止しました。私がしたことは、ダイアログを表示する前に次のコード行を追加することです。

 $('body').find("#window").remove();

したがって、jquery ダイアログを表示するラッパー関数は次のようになります。

function ui_window(title, dialogWidth, content,buttons,className)
{
  $('body').find("#window").remove();
$('<div id="window">').html(content).
  dialog({
      title: title,
      show: 'drop',
      hide: 'drop',
      width: dialogWidth,
      buttons: buttons,
      position: { my: 'center', at: 'center', of: window }
}
   ).addClass(className);
  return false;
}

一度に 1 つのダイアログのみが表示されるようになりました。ハッピーjQuerying。

于 2012-12-22T12:42:01.057 に答える