要获取当前URL,可以使用attr()
method或window.location。
<html> <head> <title>url</title> <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $("button").click(function () { alert($(location).attr('href')); alert(window.location); }); }); </script> </head> <body> <div> <button type="button" id="btn">Display URL</button> </div> </body> </html>