对混淆标题的道歉。
我有一个友好的iframe在其中的网页,并且iframe中包含一个脚本标记。本质上,它看起来像这样:
<iframe src="Javascript:'<div id=\'target\'></div><script src=\'appendStuff.js\'><\/script>'"></iframe>
appendStuff.js负荷的jQuery上document
,然后做类似下面的操作:
doc = document; // the iframe's document
$('<h1>Loaded!</h1>').appendTo('#target', doc);
这一切正常。但是,为了修复appendStuff.js中的另一个bug,我们需要移动jQuery并将其加载到window.top.document
上,而不是在iframe中的document
。
现在,.appendTo('#target', doc)
调用静静地失败,没有任何东西被追加。
这是令人难以置信的混淆,因为只选择$('#target', doc)
似乎工作得很好。
有谁知道这是否真的被打破,如果我做错了什么,或者有什么办法解决这个问题?
appendTo接收单个参数。可能你需要'$('
加载!
').appendTo($('#target',doc));' –@AlexKudryashev这是问题!非常感谢。如果你把它写成答案,我会接受它。 – Mordred