我是Jquery和Javascript的新手。我正在尝试修改this示例:w3schools将URL从最初的www.w3schools.com更改为第二个:www.w3schools.com/jquery并返回到最初的一次,当点击按钮(尽可能多次),但我不知道如何去做。请在答案中包含所有代码,这会更容易。谢谢。如何使用JQuery动态更改URL
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#w3s").attr("href", "https://www.w3schools.com/jquery");
});
});
</script>
</head>
<body>
<p>
<a href="https://www.w3schools.com" id="w3s">
W3Schools.com
</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>
首先哈弗链接,你会看到... www.w3school.com ....点击按钮链接变更后.. 。你可以检查它 –
@Miguel通过回答似乎没有理由(*也许由机器人*),无论如何它回答你的问题。其他问题只是复制您提供的代码并将其置于答案中。 –
https://www.w3schools.com/code/tryit.asp?filename=FGOSUXX5HUOG –