如何用 jQuery 获取当前 URL?
要获取当前 URL,可以使用 attr() 方法或 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>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 程序设计
C++
C#
MongoDB
MySQL
JavaScript
PHP