我正在尝试制作将在一段时间间隔后更改href的javascript。我做了点什么,但是没用...
<script>
$(document).ready(function()
{
setInterval(fetch_quote,5000);
});
function fetch_quotes() {
var x = document.getElementById("Buttonn");
if document.getElementById("Buttonn").href="#primary";{
document.getElementById("Buttonn").href="#volby";
} else {
document.getElementById("Buttonn").href="#primary";
}
}
</script>
我只是从JS开始,所以我没有很多知识...
答案 0 :(得分:0)
尝试一下
$(document).ready(function() {
setInterval(fetch_quotes, 1000);
});
function fetch_quotes() {
var x = document.getElementById("Buttonn");
// if href containces '#primary'
if (x.href.includes('#primary')) {
// set to '/#volby'
x.href = '/#volby';
} else {
// set to '/#primary'
x.href = '/#primary';
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="Buttonn" href="/#primary">