在体育运动中,每项纪录都会有作古的一天!
insertAdjacentHTML方法beforeend参数ajax加载更多评论实例页面
回到相关文章 »代码:
JS代码:
var $ = function(id) {
return {
0: document.getElementById(id),
length: 1,
click: function(fn) {
this[0].onclick = fn;
},
insertAdjacentHTML: function(position, html) {
this[0].insertAdjacentHTML(position, html);
}
}
};
$("commentMore").click(function() {
var xhr, self = this;
if (this.ajaxing) return;
if (window.XMLHttpRequest) {
xhr = new window.XMLHttpRequest();
} else {
xhr = new ActiveXObject("Microsoft.XMLHttp");
}
// 提示
this.innerHTML = '加载中...';
// 阻止二次点击
this.ajaxing = true;
// ajax go go go!
xhr.open("get", this.getAttribute("data-url"), true);
xhr.send(null);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200 && xhr.responseText) {
$("commentUl").insertAdjacentHTML("beforeend", xhr.responseText);
self.parentNode.innerHTML = '<span class="g9">全部加载完毕</span>';
self = null;
} else {
self.innerHTML = '加载失败!点击重试~';
self.ajaxing = false;
}
}
}
return false;
});
木木洁灵:马刺继续倒在总决赛之前,得重建了。 (20秒前)
回复
人心薄如纸-:记录就是拿来破的! (2分钟前)
回复
潘慶棠:单场100分也不会是尘封的记录 (4分钟前)
回复
更多评论↓