点击异步切换图片,也称异步加载数据,这就是ajax的奇特之处。
写了一个很简单的demo放到git了:http://koringz.github.io/ajax/
js:
function xmlhttp(argument) {
if(typeof ajax == 'undefined'){
try{
ajax = new XMLHttpRequest();
}
catch(e){
ajax = new ActiveXObject('Microsoft.XMLHTTP');
}
}
return ajax;
}
function getcontent (url) {
var request = xmlhttp();
request.open('get',url,true);
request.onreadystatechange = function () {
if(request.readyState == 4){
var img = '<img src="'+ url +'" />';
console.log('typeof eval(img)');
document.querySelector('.Box-inline-block').innerHTML = img;
}
}
request.send(null);
}
window. function(){
var input = gettag('input');
console.log(input + '2');
for(var i = 0; i<input.length;i++){
console.log(input[i]);
input[i].index = i;
input[i].onclick = function () {
var value = 'images/gyy' + this.index + '.jpg';
getcontent (value);
}
}
}
下载地址:https://github.com/koringz/ajax
原文链接:https://www.f2er.com/ajax/162852.html