gpt4 book ai didi

javascript - 使用 Javascript/Jquery 在单击按钮时更改 div 中的文本

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:38:03 25 4
gpt4 key购买 nike

这是数组

var copyText= [
'this is the first line',
'Simply put, the second line',
'impressed by the third line.'
];

这些都行不通...

$("#thisbutton").click(function () {
$("#thetext").innerHTML("meow meow");
});

$("#thisbutton").click(function () {
$("#thetext").innerHTML(copyText[1]);
});

$("#thisbutton").click(function () {
$("#thetext").text(copyText[1]);
});


$("#thisbutton").click(function () {
$("#thetext").html(copyText[1]);
});

我错过了什么?谢谢。

最佳答案

首先,innerHTML 是一个原生的DOMElement 属性,而不是jQuery 方法。jQueryhtml 方法是等效的。

其次,您没有将其包装在 ready 处理程序中:

试试这个:

$(function() {
var copyText= [
'this is the first line',
'Simply put, the second line',
'impressed by the third line.'
];
$("#thisbutton").click(function () {
$("#thetext").text(copyText[1]);
});

});

jsFiddle example

关于javascript - 使用 Javascript/Jquery 在单击按钮时更改 div 中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4295227/

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