我制作了一个 jquery 函数,假设执行 3 个步骤
- onload 它应该替换所有链接文件的属性
- 单击它时应将子页面加载到 $("#content")
- 再次它应该重新触发将再次替换所有链接的功能
下面的代码工作到 2 个步骤,但不会触发第三步,它应该再次替换所有 url 我认为它也应该替换加载页面的链接?
$(document).ready(function(){
var base_url = "http://localhost/dolphin/";
$("a").each(function(e){
if(this.href == "javascript:void(0)" ||
this.href == base_url ||
this.href == base_url + "index.php" ||
this.href == "javascript:void(0);" ||
this.href == "javascript:%20void(0)") {
}else{
page = 'Javascript:LoadPage(\''+ this.href + '\')';
this.setAttribute('onclick',page);
this.setAttribute('href', '#');
}
});
});
function LoadPage(url){
$("#contentarea").load(url, function() {
//after loading it should call redoIt() but it doesnt.
redoIt();
});
}
function redoIt(){
var base_url = "http://localhost/dolphin/";
$("a").each(function(e){
if(this.href == "javascript:void(0)" ||
this.href == base_url + "index.php" ||
this.href == "javascript:void(0);" ||
this.href == "javascript:%20void(0)") {
}else{
page = 'Javascript:LoadPage(\''+ this.href + '\')';
this.setAttribute('onclick',page);
this.setAttribute('href', '#');
}
});
}