jQuery 读xml并search

本文介绍了一个使用jQuery实现的简单XML数据搜索应用。该应用能够从XML文件中搜索书籍标题,并显示包含匹配项的书籍详情,包括作者和出版年份。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!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> <title>无标题页</title> <mce:script src="jquery-1.4.4.js" mce_src="jquery-1.4.4.js" type="text/javascript"></mce:script> <mce:script type="text/javascript"><!-- function search() { var searchStrLow = $("#txtTitle").val().toLowerCase(); $.get("1.xml", function(data) { var html = ""; $(data).find('book').each(function() { var titleLow = $(this).find("title").text().toLowerCase(); if (titleLow.indexOf(searchStrLow)!=-1) { html += "<tr><td>" + $(this).find("title").text() + "</td>"; html += "<td>" + $(this).find("author").text() + "</td>"; html += "<td>" + $(this).find("year").text() + "</td></tr>"; $("#tbody1").html(html); } }); }); } // --></mce:script> </head> <body> <span>输入标题:</span><input id="txtTitle" type="text" /> <input id="Button1" type="button" value="搜索" onclick="search()" /> <table style="width: 100%;"> <thead><tr><td>Title</td><td>Author</td><td>Year</td></tr></thead> <tbody id="tbody1"> </tbody> </table> </body> </html> <?xml version="1.0" encoding="utf-8" ?> <bookstore>   <book id="No1">   <title>An Introduction to XML</title>   <author>Chunbin</author>   <year>2010</year>   <price>98.0</price>    </book>   <book id="No2">   <title>The Performance of DataBase</title>   <author>John</author>   <year>1996</year>   <price>56.0</price> </book> </bookstore>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值