我可以在firebug中看到我的锚标记的路径名的值,但是我很难访问它
<script type="text/javascript">
$(document).ready(function() {
$("a").click(function() {
alert("Hi");
$.ajax({
type: "POST",
url: "NickTracker.asmx/LogActivity",
contentType: "application/json; charset=utf-8",
data: "{'path': '" + attr('pathname') + "'}",
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed
});
});
});
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
</script>
Run Code Online (Sandbox Code Playgroud)
这是我的HTML
<body>
<form id="form1" runat="server">
<div>
Page 1<br />
<br />
<a href="http://manual.aspdotnetstorefront.com/p-157-xml-packages.aspx">Manual</a>
<br />
<a href="http://www.google.com/">googles</a>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
Run Code Online (Sandbox Code Playgroud)
当用户点击我想要返回的路径时,这不是work-attr('pathname')
您需要引用this对象和正确的属性,所以更换attr('pathname')用$(this).attr('href'),甚至更简单this.href
this.pathname只会在URL主机名后访问任何值,如果您在站点上遍历根目录相关文件,则可以正常运行,但如果您尝试访问其他主机上的文件,则会中断.例如,因为href="http://www.google.com/finance",this.pathname将导致公正/finance
| 归档时间: |
|
| 查看次数: |
2797 次 |
| 最近记录: |