[英]Do something with ajax-loaded iframe content?
我通過 fancybox 將一些內容(簡單的 web 形式)加載到 iframe(來自我的域)。 並希望為這個 iframe 表單中的一個輸入添加值。
試試這個:
$x("a.load_html_i").fancybox({
'type' :'iframe',
'padding' : 20,
'width' : 690,
'height' : 550,
'onComplete' : function() {
$x('#fancybox-frame input[name=input_text_0]').val($x(this).attr('title'));
}
});
其中#fancybox-frame 是 iframe 的 ID。
還有這個:
...
$x("#fancybox-frame").contents().find("input[name=input_text_0]").val($x(this).attr('title'));
...
但這是行不通的。
不要使用“this”關鍵字,而是通過名稱 class 引用錨點。 我相信“this”引用的是 fancybox 實例化。
$x("a.load_html_i").fancybox({
'type' :'iframe',
'padding' : 20,
'width' : 690,
'height' : 550,
'onComplete' : function() {
//cache the anchor
var anchor = $x(this);
//trigger the following function in 0.5s (should be long enough)
setTimeout(function(){
$x('#fancybox-frame input[name=input_text_0]').val(anchor.attr('title'));
}, 500);
}
});
我發現一個問題:jquery 在 iframe 加載之前運行。 如何改進?
$x("iframe#fancybox-frame").ready(function(){
$x("iframe#fancybox-frame").contents().find("input[name=input_text_0]").val('hh');
});
添加准備好無濟於事
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.