1

简单的问题......也许?基本上我想要做的是将文本插入到页面上加载的 URL 的末尾。所以在我的页面上我会有类似...

<a href="myurl.html">My Url</a>

我想要的是在点击事件的文件扩展名之后附加文本。所以点击后它应该看起来像..

<a href="myurl.html#something">My Url</a>

$('a').click(function(){
  //add text to url
});
4

1 回答 1

2

您可以使用或更改href属性。.prop().attr()

$("a").click(function() {
    $(this).prop("href", $(this).prop("href") + "#something");
});

或者

$("a").click(function() {
    $(this).attr("href", $(this).attr("href") + "#something");
});
于 2012-05-29T15:29:27.300 回答