url:http://www.darlingbank.com/cutpage/index.php/promote/edit/getfun/json/
源碼:
<ul class="cf" dataurl="http://www.paipai.com/sinclude/xml/tjw/tjw2014/tjw4/tjw179255804475.js" commlen="4" commsta="1" commtpl='<li><a href="{#recmdReason#}" target="_blank">{#recmdRegName#}</a></li>'>
js:
var J_data = { debug : true, log : function(s){ this.debug && (window.console ? console.log(s) : alert(s)); }, create_script : function(src){ var Scrip=document.createElement('script'); Scrip.charset="gbk"; Scrip.src=src; document.body.appendChild(Scrip); }, get : function(){ var thats=this; $("[dataurl]").each(function () { var that=this; dataurl=$(this).attr("dataurl"), tpl_tmp=$(this).attr("commtpl"); if(typeof tpl_tmp==='undefined' || tpl_tmp===''){ thats.log('请填写模板'); }else{ var c_str=dataurl.slice(dataurl.lastIndexOf('/')+1).split('.')[0]; window[c_str]=function(j){ var d=j.data.adList,html='', len=parseInt($(that).attr("commlen")) || d.length, start=parseInt($(that).attr("commsta")) || 0, tpl=$(that).attr("commtpl"); if(start>0 && len<d.length){ len +=start; } for(var i=start;i<len;i++){ html += tpl.replace(/{#recmdReason#}/g,d[i].recmdReason).replace(/{#recmdRegName#}/g,d[i].recmdRegName).replace(/{#image#}/g,d[i].image).replace(/{#adSentence#}/g,d[i].adSentence); } $(that).html(html); } // $.getScript(dataurl+"?callback="+c_str); //亦可以用jquery方法 thats.create_script(dataurl+"?callback="+c_str); } }); } } $(function(){ J_data.get(); })