【发布时间】:2016-10-23 18:11:16
【问题描述】:
请帮忙,我明白为什么 ajax 链接在点击时有效或无效? 它会随着时间的推移而起作用
window.onload = function(){
function getXmlHttp(){
...... // simply ajax
}
var cont = document.getElementById('wrapper1');
var As = document.getElementsByTagName("A"); // get links
for(var i = 0, l = As.length; i < l; i ++){
As[i].onclick = function(href){ // code
As[i].addEventListener('click', false); // code
return function(e){
e.preventDefault();
var xmlhttp = getXmlHttp()
xmlhttp.open('GET', href, false);
xmlhttp.send(null);
if(xmlhttp.status == 200) {cont.innerHTML = xmlhttp.responseText;}
}
}(As[i].href);
As[i].href = "javascript: void 0"; // right code ?
}
}
【问题讨论】:
标签: javascript php jquery jquery-ui jquery-plugins