[英]Safari : jQuery functionality not working in ajax loaded content
我有一个页面dashboard.asp
它打开一个对话框并使用 ajax 加载... profile.asp
在profile.asp
中有各种与配置文件功能相关的 jquery 函数。 一切都好接受 Safari 不会加载$(document).ready
在加载的内容中。
第二个问题是我是否应该在 ajax 加载页面以及父页面中包含<script src="jquery.js"></script>
。
dashboard.asp
中的代码
<script language="javascript">
$(document).ready(function(){
$("a[rel=profile]").live('click',function() {
var profileURL = $(this).attr('href');
var title = $(this).attr('title');
$.ajax({
url: profileURL,
cache: false,
success: function(data) {
$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
$("#overlayer").fadeIn();
$('#profile_menu_wrapper').load('/profile.asp',{a:title},function(){
$('#profile_menu_wrapper').fadeIn(1000);
$("#profile").html(data);
$("#profile").fadeIn(1000);
});
}
});
return false;
});
});
</script>
哪个工作正常并根据我的需要打开一个对话框......
但是profile.asp
中的代码
<script language="javascript">
$(document).ready(function(){
alert("Ready")
});
</script>
不跑...
修改profile.asp中的代码如下:
<script language="javascript">
$(document).ready(InitProfileJqueryFunctionality);
function InitProfileJqueryFunctionality() {
alert("Some stuff");
}
</script>
然后更改 Dashboard.asp 中的代码,以在加载的页面中调用 function(如果存在)。
<script language="javascript">
$(document).ready(function(){
$("a[rel=profile]").live('click',function() {
$("#profile").hide();
var profileURL = $(this).attr('href');
var title = $(this).attr('title');
$.ajax({
url: profileURL,
cache: false,
success: function(data) {
$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
$("#overlayer").fadeIn();
$('#profile_menu_wrapper').load('/profile.asp',{a:title},function(){
$('#profile_menu_wrapper').fadeIn(1000);
$("#profile").html(data);
$("#profile").fadeIn(1000);
if (typeof(InitProfileJqueryFunctionality) != 'undefined')
InitProfileJqueryFunctionality();
});
}
});
return false;
});
});
</script>
我想说在 profile.asp 页面中保留对加载 jQuery.js 的引用是个好主意,因为这样可以让您灵活地正常打开该页面(例如,不通过 AJAX)并让它仍然工作。
啊!
我在 Ajax 加载的内容中留下了<html><body>
等,这一切都搞砸了!
感谢您的回答,因为它们在上下文中是正确的,所以支持它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.