標籤:http color java io ar 資料 div cti 代碼
依據HTML模板返回解析的XML
依賴jQuery 1.4
?1. [代碼]基於Jquery的xml解析器並返回定製的HTML
/**
* jQuery外掛程式
* Author: [email protected]
* Date : 2011-02-16
* Params: dom:XMLDocument ,
* _default:{
* reg:匹配標籤正則,
* lc:標籤左結束符,
* rc:標籤右結束符,
* script:是否包含script,
* scriptID:包含script的節點,
* tplBox:模板,
* tplhtml:資訊條目
* }
* Return: HTMLDocument
* Note : XML處理外掛程式
*
*/
(function($){
$.fn.extend({
parseXML:function(dom,option){
var that=$(dom);
var html={};
var tpl=‘‘;
//配置資料
var _default={
reg:/\{\w+\}/gi,
lc:‘{‘,
rc:‘}‘,
script:true,
scriptID:‘script‘,
tplBox:‘<ul class="indexiframelist skin3">{item}</ul>{more}‘,
tplhtml:{
item:‘<li><a href="{link}"><span class="timer">{pubDate}</span>{title}</a></li>‘,
more:‘<div class="moreLink"><a href="{link}">{title}</a></div>‘,
script:‘function {funcationname}{{funcationcode}}‘
}背景音樂http://www.huiyi8.com/bgm/?
}
var option=$.extend(_default,option);
//開始處理tplBody
$.each(option.tplhtml,function(o,str){
var rego=str.match(option.reg);
html[o]=[];
$(o,that).each(function(){
var D=$(this),shtml=str;
$.each(rego,function(i,c){
shtml=shtml.replace(c,D.find(c.replace(option.lc,‘‘).replace(option.rc,‘‘)).text());
});
html[o].push(shtml);
});
});
//開始處理tplBox
var tplHtml=option.tplBox;
tpl=option.tplBox.match(option.reg);
$.each(tpl,function(i,c){
tplHtml=tplHtml.replace(c,html[c.replace(option.lc,‘‘).replace(option.rc,‘‘)].join(‘‘));
});
//向頁面添加script
if(option.script){
var script=document.createElement(‘script‘);
script.type="text/javascript";
script.text=html[option.scriptID].join(‘‘);
$(‘html > head‘).append(script);
}
return tplHtml;
}
});
})(jQuery);
?
基於Jquery的XML解析器,返回定製的HTML