jQuery 读xml并search
<!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="搜索" οnclick="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>