Jquery加载元素页面可以处理除视频以外的所有内容
这是密码Jquery加载元素页面可以处理除视频以外的所有内容,jquery,video,Jquery,Video,这是密码 $(function() { if(location.hash) $("#content_inload").load(location.hash.substring(1) + ' #content_inload'); $("#nav a").click(function() { $("#content_inload").load(this.hash.substring(1) + ' #content_inload'); }); }); 出于某
$(function() {
if(location.hash) $("#content_inload").load(location.hash.substring(1) + ' #content_inload');
$("#nav a").click(function() {
$("#content_inload").load(this.hash.substring(1) + ' #content_inload');
});
});
出于某种原因,它将加载所有内容,但不会加载jw视频播放器。但是,如果我要求它加载整个页面,而不仅仅是“#content_inload”,它将加载视频,即使该页面没有标题部分,没有脚本,也不超过“#content_inload”中的内容。我只能假设JW播放器在内容顶部的底部添加了一行代码,但找不到那一行是什么。如果您看到jquery的源代码,了解它们使用的
.load()
方法
...
self.html(
selector ?
// Create a dummy div to hold the results
jQuery("<div>")
// inject the contents of the document in, removing the scripts
// to avoid any 'Permission Denied' errors in IE
.append(res.responseText.replace(rscript, ""))
// Locate the specified elements
.find(selector) :
// If not, just inject the full result
res.responseText
);
...
还请注意,我使用了#inload_容器
作为目标元素,因为您正在将#content_inload
插入自身,实际上是复制
更新 在你发表评论之后,我尝试了以下有效的方法
$("#nav a").click(function() {
$.get( this.hash.substring(1), function(response){
$("#inload_container").empty().append(response).find('>*:not(#content_inload)').remove();
} );
});
在内存jquery对象中创建脚本元素时,似乎会出现问题?(无法确定原因)
在您的特定情况下,上述解决方案可以工作,但它不是很优雅,因为它将从ajax调用返回的所有内容添加到DOM中,然后过滤掉我们不想要的内容
如果您看到jquery的源代码中关于
.load()
方法的内容,那么最好只更改实际的视频页面(从ajax加载的页面),然后执行正常的.load()
,而不过滤任何内容
...
self.html(
selector ?
// Create a dummy div to hold the results
jQuery("<div>")
// inject the contents of the document in, removing the scripts
// to avoid any 'Permission Denied' errors in IE
.append(res.responseText.replace(rscript, ""))
// Locate the specified elements
.find(selector) :
// If not, just inject the full result
res.responseText
);
...
还请注意,我使用了#inload_容器
作为目标元素,因为您正在将#content_inload
插入自身,实际上是复制
更新 在你发表评论之后,我尝试了以下有效的方法
$("#nav a").click(function() {
$.get( this.hash.substring(1), function(response){
$("#inload_container").empty().append(response).find('>*:not(#content_inload)').remove();
} );
});
在内存jquery对象中创建脚本元素时,似乎会出现问题?(无法确定原因)
在您的特定情况下,上述解决方案可以工作,但它不是很优雅,因为它将从ajax调用返回的所有内容添加到DOM中,然后过滤掉我们不想要的内容
完全改变实际的视频页面(从ajax加载的页面)并执行正常的
.load()
,而不过滤任何内容,这样做可能会更好。在(单击测试视频)上的示例。加载的页面中到底有什么内容?(仅此而已)如果我告诉它加载整个页面,而不仅仅是“#content_inload”,但“#content_inload”是整个页面,那么一切都很好。只是一个测试问题的示例,这不是最终结果。您所说的“jw视频播放器”是什么?出现错误(inloader.js,第15行,未定义)。能否先修复此错误以排除依赖项。示例位于(单击测试视频)。加载的页面中到底有什么内容?(仅此而已)如果我告诉它加载整个页面,而不仅仅是“#content_inload”,但“#content_inload”是整个页面,那么一切都很好。只是一个测试问题的示例,这不是最终结果。您所说的“jw视频播放器”是什么?出现错误(inloader.js,第15行,未定义)。能否先修复此错误以排除依赖项。感谢您告诉我IE问题。已实现您的代码,但仍无法加载视频。如果脚本没有定义要加载的元素,视频才会加载。感谢您告诉我IE问题。已实现您的代码,但仍无法加载视频。仅当脚本未定义要加载的元素时,才会加载视频。