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 に答える