我的问题是,当我通过javascript更改href属性时,新的href附加到了网站网址中 the main link before change using jquery
我更改href
之后 $(".buttonSec").prop("href", "my_wanted_href");
网址类似
page URL after the change on the buttonSec
我要的是如何使此URL不附加链接 使用jQuery
答案 0 :(得分:0)
尝试使用 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>