日期:2014-05-16 浏览次数:20362 次
<!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>ajax整站入口页</title> <script type="text/javascript" src="jquery-1.6.4.min.js" ></script> <script type="text/javascript" > var ahref; function convertAtoAjax(o) { $(o).find("a").each(function() { $(this).attr("href", "#" + $(this).attr("href")); $(this).click(function() { ahref = $(this).attr("href"); getajax(); }); }); } function getajax() { $.get(ahref.substr(1), function(data) { $("#content").html(data); convertAtoAjax("#content"); }); } $(document).ready(function() { convertAtoAjax("body"); var r = window.location.href.match(/#.*$/); if (r) { ahref = r[0]; getajax(); } }); </script> <style type="text/css" > #content{border:1px solid red;} </style> </head> <body> <div id="nav"> <a href="ajax1.htm">页1</a> <a href="ajax2.htm">页2</a> </div> <div id="content">welcome to ajax home</div> </body> </html>