使用jQuery向iFrame中的表添加行(直播?) [英] Adding a row to a table in an iFrame with jQuery (live?)
问题描述
我有一个页面正在加载一个iFrame,它根据用户点击的链接来源。 iFrame返回一个我需要添加一行的小表。
I have a page that is loading an iFrame that has it's source based on what link the user clicks. The iFrame returns a small table that I need to add a row to.
我的问题是我需要使用像.live或.delegate这样的东西,因为iFrame没有加载在document.ready上。如何将.append绑定到iFrame加载上的.live或.delegate而不是点击或鼠标悬停类型函数?
My issue is that I need use something like .live or .delegate as the iFrame is not loaded on document.ready. How do I tie the .append to a .live or .delegate on the iFrame load and not a click or mouseover type function?
我试过:
$(document).ready(function(){
$('#click').click(function(){
$('#myFrame').attr('src', 'http://iframe_link_here/');
});
// Add the new row
$('<tr><td>New Row</td><td>goes here</td></tr>').appendTo('#myTable');
});
但由于表格不在document.ready上,因为我想添加这个在iFrame加载上排,只是不知道如何附加到它。
but as the table isn't there on document.ready, and since I am wanting to add this row on the iFrame load, and just don't know how to attach to it.
感谢您的帮助。
推荐答案
只是一个想法:
$(document).ready(function(){
$('#click').click(function(){
$('#myFrame').attr('src', 'http://iframe_link_here/');
});
$('#myFrame').on('load',function(){
// Add the new row
$('<tr><td>New Row</td><td>goes here</td></tr>').appendTo('#myTable');
});
});
编辑: .live()
现已弃用,因此应改为使用 .on()
。
EDIT: .live()
is now deprecated, so .on()
should be used instead.
这篇关于使用jQuery向iFrame中的表添加行(直播?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!