//Html - page containing link to open dialog
<input type="text" value="something" id="inputbox_id" />
<a href="#" class="opendialog">Open</a>
//Javascript
.opendialog.click function
{
$('.modaldialog').click(function(event) {
$('<div id="dialogContainer"> </div>').appendTo('body');
//ajax call to page.php, if successful then add output of page.php to
//dialogContainer div created above
//page.php has a button and some javascript as below
}
//Html - content of page.php
<input type="button" id="button" value="I am button" />
//Javascript on page.php
// On click "#button"
// $('#inputbox_id').val("Something New");
代わりに「inputbox_idが定義されていません」というエラーが表示されました....
だから私はコードを
$('#input_box_id', 'body').val(); // didn't work
$('body').find('#input_box_id').val("some value"); //Worked
私の質問は -
この場合、$(selector, context) セレクターが機能しなかったのはなぜですか? select body を使用してから必要な要素を見つけても問題ありませんか? もっと良いものを提案していただけますか?
#button をクリックした後にこのダイアログを閉じるにはどうすればよいですか?
私はあなたの助けに感謝します!
アップデート
ダイアログを閉じる問題が解決されました - $("#IdOfDialogContainer").remove(); を呼び出すだけです。