そのようなイベントがないことは知っていますが、私が使用できる同様のものはありますか?
コンテナに動的にロードされるASP.NETユーザーコントロールがあり、非常にスムーズな効果が得られます。
これを行うことの欠点は、コントロールの読み込みが完了したときにクライアント側の JavaScript を実行したいのですが、その方法がわからないことです。
jQuery スクリプトが実行されなかった理由を理解するのにしばらく時間がかかりましたが、その後、それらは実行されただけで$(document).ready()
あり、それはページ全体が読み込まれたときにのみ発生することに気付きました! (当たり前!)
誰でもこれを行う方法を考えることができますか?
ありがとう :)
今より複雑になっています!
コンテナが変更されたときにスクリプトを実行できるように、DOM Mutation Observer を使用してコンテナを監視しようとしています。
しかし、私はエラーが発生しています:An attempt was made to reference a Node in a context where it does not exist.
DOM 要素は存在しますが、エラーを正しく理解しているかどうかわかりません。
ここに私のオブザーバーコードがあります:
$(document).ready(function () {
// select the target node
var target = $('#contentPanel');
if (typeof (target) != 'undefined') {
// create an observer instance
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
console.log(mutation.type);
if (mutation.addedNodes) {
alert('New nodes');
}
//rememberMe();
})
});
// configuration of the observer:
var config = { attributes: false, childList: true, characterData: true }
// pass in the target node, as well as the observer options
observer.observe(target, config); // <== error occurs here
}
});
最終的なオブザーバー コード:
$(document).ready(function () {
// select the target node
var target = $('#contentPanel');
if (typeof (target) != 'undefined') {
// create an observer instance
var observer = new MutationObserver(function (mutations) {
var doRememberMe = false;
mutations.forEach(function (mutation) {
if (mutation.addedNodes) {
doRememberMe = true;
}
})
if (doRememberMe) rememberMe();
});
// configuration of the observer:
var config = { attributes: false, childList: true, characterData: true }
// pass in the target node, as well as the observer options
//observer.observe(target, config);
observer.observe(document.body, config); // <== apply observer to whole document! (could be done nicer)
}
});