我一直在JS编码一段时间,但不知何故,我总是得到一个'刮头'类型的问题。我认为我需要进行一些挖掘,但同时有人可以帮助解决这个问题?load()API调用函数回调范围
所以,这里是问题: 我正在通过该项(通过$(this)得到)到回调函数中。此代码不起作用 - 当我真的认为它应该。因为我已经将$(this)放入一个变量(克隆数据?),然后通过函数将它传递给回调函数,那么它肯定不会丢失数据?但它确实和可怕
// Allow hrefs with the class 'ajax' and a rel attribute set with a selector to load via ajax into that selector.
$(".ajax").unbind("click").click
(
function(e)
{
var locationhint = $(this).attr("rel");
var $location = $(locationhint);
$location.html ("<img src='images/blockloading.gif' />");
$location.load($(this).attr("href").replace("index.php", "ajax.php"), '', function($location){dready($location);});
e.preventDefault();
}
);
现在不起作用。
这一个工程:
$(".ajax").unbind("click").click
(
function(e)
{
$("#myspecificdiv").load($(this).attr("href").replace("index.php", "ajax.php"), '', function(){dready($("#myspecificdiv"));});
e.preventDefault();
}
);
我把它这是一个范围的问题,而且我也做到了这一点,这应该的工作,因为它是完全一样的“静态”一个以上,本质上是因为它传递了元素的文本ID。 这一个也打破了:。
$(".ajax").unbind("click").click
(
function(e)
{
var locationhint = $(this).attr("rel");
var $location = $(locationhint);
$location.html ("<img src='images/blockloading.gif' />");
var locationid = "#" + $location.attr("id");
$location.load($(this).attr("href").replace("index.php", "ajax.php"), '', function(locationid){dready($(locationid));});
e.preventDefault();
}
);
破碎的,当我console.log locationid,返回目标DIV的内部HTML。 $ location.attr( “ID”);当没有其他地方的电话肯定会返回原始的HTML?所以这是我接受的范围?但是,如何让内部的HTML被吐出?
任何解决方案?
更新: 12秒后我张贴了这个它发生,我认为函数($位置){DREADY($位置);}在回调可能会自动地通过AJAX调用响应内部功能?但为什么?