使用jQuery消失指向URL的链接



我的问题是当我通过JavaScript更改HREF属性时,新的HREF附加到网站URL中使用jQuery

更改之前的主要链接

我更改href

 $(".buttonSec").prop("href", "my_wanted_href");

URL就像

page url the Buttonsec上的更改后

我想要的是如何使此URL不附加链接使用jQuery

尝试使用 attr 属性而不是 prop 尝试下面的代码。

$(document).ready(function(){
  $("button").click(function(){
    $("#stack").attr("href", "https://google.com");
  });
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<p><a href="https://www.stackoverflow" id="stack">STACKOVERFLOW</a></p>
<button>Change href Value</button>
<p>Mouse over the link (or click on it) to see that the value of the href attribute has changed.</p>
</body>
</html>

最新更新