ajax异步加载
点击异步切换图片,也称异步加载数据,这就是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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |