[JS]用js来读取xml文件的信息
js读写本地xml文件,[JS]用js来读取xml文件的信息
[JS]用js来读取xml文件的信息
- <!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
- <title>js读取xml</title>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
- type="text/javascript"></script>
- <script type="text/javascript">
- //酷播cuplayer.com提示:使用jquery框架事半功倍
- $(document).ready(function(){
- var imageID;
- var xml;
- loadXML("test.xml");
- $("#imgInfo").find("img").mouseover(function(){
- //酷播cuplayer.com提示:鼠标移入imgInfo里的IMG
- imageID=$(this).attr("id");
- //酷播cuplayer.com提示:获取移入图片的ID
- $(xml).find("Image").each(function(){
- //遍历xml的image标签
- if($(this).attr("ID")==imageID)
- //相等设置输出
- $("#output").html("ID:"+$(this).attr("ID")+",TT:"+$(this).attr("TT")+",Time:"+$(this).attr("Time"))
- })
- })
- $("#imgInfo").find("img").mouseout(function(){//鼠标移出
- $("#output").html("")//清空
- )}
- function loadXML(fileName) {//ajax方式读取xml
- $.ajax({
- type: "GET",
- url: fileName,
- dataType: ($.browser.msie) ? "text" : "xml",
- success: function(data, textStatus, jqXHR){//读取成功
- if (typeof data == "string") {
- xml = new ActiveXObject("Microsoft.XMLDOM");
- xml.async = false;
- xml.loadXML(data);
- } else {
- xml = data;
- }
- },
- error: function(jqXHR, textStatus, errorThrown) {//读取失败时
- _defaultAjaxError(jqXHR, textStatus, errorThrown);
- }
- });
- }
- function _defaultAjaxError(jqXHR, textStatus, errorThrown) {
- alert(jqXHR.status + ' * ' + jqXHR.statusText + ' * ' + jqXHR.responseText );
- alert(textStatus);
- }
- });
- </script>
- </head>
- <body>
- <div id="imgInfo">
- <image src="http://album.u17i.com/image/2011/11/ea/36/470344_28309_165138_tkBE.jpg" ID="566" />
- <image src="http://album.u17i.com/image/2011/11/95/5a/482698_29371_165138_MROI.jpg" ID="786" />
- </div>
- <div id="output"style="color:red">酷播cuplayer.com提示:输出信息</div>
- </body>
- </html>
[JS]用js来读取xml文件的信息
xml内容信息:
- <?xml version="1.0" encoding="UTF-8"?>
- <root>
- <Image TT="pic1" Time="546754" ID="566"/>
- <Image TT="pic2" Time="678844" ID="786"/>
- </root>
出处http://blog.csdn.net/yukon12345
热门文章推荐
- [JS]window.location获取url各项参数详解
- [JS]jQuery,javascript获得网页的高度和宽度
- [JS]视频弹窗视频弹出层videoLightBox(含三种播放器的用法)
- [JS]JS提交中文encodeURI两次转码
- [JS]js版方面encodeURI转码和decodeURI解码的用法实例
- [JS]js取当前机子的时间戳实例
- [JS]AES加密(基于crypto-js)PHP后端解密
- [JS]data:image/png;base64写法的用途及说明
请稍候...