如何用 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