这是数组
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
方法。
jQuery
的 html
方法是等效的。
其次,您没有将其包装在 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]);
});
});
关于javascript - 使用 Javascript/Jquery 在单击按钮时更改 div 中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4295227/