日期:2014-05-16 浏览次数:20329 次
var xmlhttp = new window.XMLHttpRequest(); xmlhttp.open("GET",xml,false); xmlhttp.send(null); xmlDoc = xmlhttp.responseXML.documentElement;
<!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>