谁能把这段JS改成JS+XML???

vinjuviva 2010-01-29 03:45:36
我想把数组imag、link、text的值改成从XML获取,我想取出XML的最新的5条数据记录(时间排序),或者说如何取得XML+XSL的结果记录??其实这是一个图片轮换的特效!!我想改成动态!!注意XML的Article中的ID属性不是一定是按顺序排列的!

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="Flash.xsl"?>
<TopArt>
<Article id="38">
<title>1111111111111</title>
<artimg>~/Newspic/20100127114516.jpg</artimg>
<arturl>Newscenter38.html</arturl>
<times>2010-1-27 11:45:16</times>
</Article>
<Article id="39">
<title>22222222222222222</title>
<artimg>~/Newspic/20100127031501.jpg</artimg>
<arturl>Newscenter39.html</arturl>
<times>2010-1-27 15:15:01</times>
</Article>
<Article id="40">
<title>333333333333333333</title>
<artimg>~/Newspic/20100127031511.jpg</artimg>
<arturl>Newscenter40.html</arturl>
<times>2010-1-27 15:15:11</times>
</Article>
<Article id="41">
<title>4444444444444444</title>
<artimg>~/Newspic/20100127031521.jpg</artimg>
<arturl>Newscenter41.html</arturl>
<times>2010-1-27 15:15:21</times>
</Article>
<Article id="42">
<title>5555555555555555</title>
<artimg>~/Newspic/20100127031533.jpg</artimg>
<arturl>Newscenter42.html</arturl>
<times>2010-1-27 15:15:33</times>
</Article>
<Article id="43">
<title>6666666666666666666666</title>
<artimg>~/Newspic/20100127034456.jpg</artimg>
<arturl>Newscenter43.html</arturl>
<times>2010-1-27 15:44:56</times>
</Article>
</TopArt>


<script type="text/javascript">
var pic_width=453;
var pic_height=230;
var button_pos=1;
var stop_time=5000;
var show_text=0;
var txtcolor="000000";
var bgcolor="DDDDDD";
var imag=new Array();
var link=new Array();
var text=new Array();
imag[1]="flashimg/01.jpg";
link[1]=escape("http://tms.taoke.alimama.com/tms/topic.php?pid=mm_13259455_0_0&eventid=100829");
text[1]="Orange-s - 桔子导购网";
imag[2]="flashimg/02.jpg";
link[2]=escape("http://tms.taoke.alimama.com/tms/topic.php?pid=mm_13259455_0_0&eventid=100839");
text[2]="Orange-s - 桔子导购网";
imag[3]="flashimg/03.jpg";
link[3]=escape("http://tms.taoke.alimama.com/tms/topic.php?pid=mm_13259455_0_0&eventid=100885");
text[3]="Orange-s - 桔子导购网";
imag[4]="flashimg/04.jpg";
link[4]=escape("http://tms.taoke.alimama.com/tms/topic.php?pid=mm_13259455_0_0&eventid=100891");
text[4]="Orange-s - 桔子导购网";
imag[5]="flashimg/05.jpg";
link[5]=escape("http://tms.taoke.alimama.com/tms/topic.php?pid=mm_13259455_0_0&eventid=100895");
text[5]="Orange-s - 桔子导购网";
var swf_height=show_text==1?pic_height+20:pic_height;
var pics="", links="", texts="";
for(var i=1; i<imag.length; i++){
pics=pics+("|"+imag[i]);
links=links+("|"+link[i]);
texts=texts+("|"+text[i]);
}
pics=pics.substring(1);
links=links.substring(1);
texts=texts.substring(1);
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cabversion=6,0,0,0" width="'+ pic_width +'" height="'+ swf_height +'">');
document.write('<param name="movie" value="flash/focus.swf">');
document.write('<param name="quality" value="high"><param name="wmode" value="opaque">');
document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'">');
document.write('<embed src="flash/focus.swf" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'" quality="high" width="'+ pic_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');
</script>
...全文
72 6 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
浴火_凤凰 2010-01-30
  • 打赏
  • 举报
回复
就是DOM遍历嘛,楼主可以在网上搜一搜啊
vinjuviva 2010-01-30
  • 打赏
  • 举报
回复
3楼的能给出例子吗???
打字员 2010-01-29
  • 打赏
  • 举报
回复
用Ajax请求XML;

解析XML并以[[id1, title1, url1, time1],[id2, title2, url2, time2]...]的形式存贮;

写一个排序,根据id或time重排数组;

取前N个

剩下的就和你的JS差不多了。
sunxing007 2010-01-29
  • 打赏
  • 举报
回复
你可以在这个基础上作修改,我只在ie6下测试过。仅供参考:

<html>
<head>
<title>flash show</title>
<style>
</style>
<body>
<a href="http://blog.csdn.net/sunxing007">http://blog.csdn.net/sunxing007</a><br />
<script type="text/javascript">
var pic_width=453;
var pic_height=230;
var button_pos=1;
var stop_time=5000;
var show_text=0;
var txtcolor="000000";
var bgcolor="DDDDDD";
var imag=new Array();
var link=new Array();
var text=new Array();

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load("book.xml");//注意:这里的路径要换成server_path/app_path/folder/book.xml
var imgs = xmlDoc.selectNodes("/TopArt/Article/artimg/text()");
var links = xmlDoc.selectNodes("/TopArt/Article/arturl/text()");
var texts = xmlDoc.selectNodes("/TopArt/Article/title/text()");
for(var i=0; i<5; i++){
imag[i] = imgs[i].xml;
link[i] = links[i].xml;
text[i] = texts[i].xml;
}

var swf_height=show_text==1?pic_height+20:pic_height;
var pics="", links="", texts="";
for(var i=0; i<imag.length; i++){
pics=pics+("|"+imag[i]);
links=links+("|"+link[i]);
texts=texts+("|"+text[i]);
}
pics=pics.substring(1);
links=links.substring(1);
texts=texts.substring(1);
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cabversion=6,0,0,0" width="'+ pic_width +'" height="'+ swf_height +'">');
document.write('<param name="movie" value="flash/focus.swf">');
document.write('<param name="quality" value="high"><param name="wmode" value="opaque">');
document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'">');
document.write('<embed src="flash/focus.swf" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'" quality="high" width="'+ pic_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');
</script>
</body>
</html>
vinjuviva 2010-01-29
  • 打赏
  • 举报
回复
别沉,赶用的!!!
发帖
JavaScript

8.7w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2010-01-29 03:45
社区公告
暂无公告