gpt4 book ai didi

javascript - 为什么这个 javascript 不能运行?

转载 作者:行者123 更新时间:2023-11-30 12:55:18 25 4
gpt4 key购买 nike

有人为我创建了这段代码: http://jsfiddle.net/kzFWa/

var downloadButton = document.getElementById("continue");
var counter = 60;
var newElement = document.createElement("p");
newElement.innerHTML = "<h3>or click here to continue in 60 seconds</h3>";
var id;

downloadButton.parentNode.replaceChild(newElement, downloadButton);

id = setInterval(function() {
counter--;
if(counter < 0) {
newElement.parentNode.replaceChild(downloadButton, newElement);
//newElement.innerHTML = "<a href="survey.php">Click Me To Continue</a>"
clearInterval(id);
} else {
newElement.innerHTML = "<h3>or click here to continue in " + counter.toString() + " seconds.</h3>";
}
}, 1000);

但是,如果我改变

newElement.parentNode.replaceChild(downloadButton, newElement); 

newElement.innerHTML = "<a href="survey.php">Click Me To Continue</a>"

代码将不再运行。我做错了什么?

最佳答案

你有一个语法错误:

newElement.innerHTML = "<a href="survey.php">Click Me To Continue</a>"

不能在这样的双引号字符串中使用双引号。要么转义,要么改成单引号和双引号的组合:

newElement.innerHTML = '<a href="survey.php">Click Me To Continue</a>';

关于javascript - 为什么这个 javascript 不能运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19379078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com