加载内容并将内容分开 V/S 加载 iframe?
Load content and the separate the content V/S load iframe?
我正在与 jquery 合作,我有一个问题涉及从服务器加载内容,将内容与页面上已有的其他内容分开,然后当内容(来自服务器)时立即已加载,做一些 dom 操作。
我遇到的问题是一些 css 样式被覆盖了。
我面临两种情况:
1) 根据我的阅读,您可以使用 jquery load() 方法从服务器加载内容,然后提供一个回调 运行 当内容完成加载时。但是我无法将内容样式和一些 javascript 函数与 运行ning.
分开
这是我正在使用的 jquery 代码:
$('#ContentIn').load('the_url_of_the_content_to_load', callback_function_to_run())
但是在第一种情况下,我无法将服务器上的内容与页面上已有的内容分开。
2) 然后我尝试像这样使用 iframe:
$('#ContentIn').append( '<iframe src="' + object.responseJSON.the_url + '"></iframe>' );
请注意,我正在使用 Ajax 获取 url,然后我成功地将 iframe 注入当前页面的正文。
但是在第二种情况下,我无法在 iframe 完成加载内容后立即运行一个函数。
希望得到解答,
MMK
你可以试试这个:-
$('#ContentIn').append( '<iframe onload="myfunction()" src="' + object.responseJSON.the_url + '"></iframe>' );
function myfunction()
{
//write your code here
}
我正在与 jquery 合作,我有一个问题涉及从服务器加载内容,将内容与页面上已有的其他内容分开,然后当内容(来自服务器)时立即已加载,做一些 dom 操作。
我遇到的问题是一些 css 样式被覆盖了。
我面临两种情况:
1) 根据我的阅读,您可以使用 jquery load() 方法从服务器加载内容,然后提供一个回调 运行 当内容完成加载时。但是我无法将内容样式和一些 javascript 函数与 运行ning.
分开这是我正在使用的 jquery 代码:
$('#ContentIn').load('the_url_of_the_content_to_load', callback_function_to_run())
但是在第一种情况下,我无法将服务器上的内容与页面上已有的内容分开。
2) 然后我尝试像这样使用 iframe:
$('#ContentIn').append( '<iframe src="' + object.responseJSON.the_url + '"></iframe>' );
请注意,我正在使用 Ajax 获取 url,然后我成功地将 iframe 注入当前页面的正文。
但是在第二种情况下,我无法在 iframe 完成加载内容后立即运行一个函数。
希望得到解答,
MMK
你可以试试这个:-
$('#ContentIn').append( '<iframe onload="myfunction()" src="' + object.responseJSON.the_url + '"></iframe>' );
function myfunction()
{
//write your code here
}