这是数组
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]);
});
我缺少什么? THKS。
答案 0 :(得分:6)
首先,innerHTML
是本机DOMElement
属性,而不是jQuery
方法。
jQuery
的{{1}}方法就是等价的。
其次,你没有将它包装在html
处理程序中:
试试这个:
ready
<强> jsFiddle example 强>
答案 1 :(得分:1)
这对我有用......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<div id="thetext">
</div>
<input type="button" id="thisbutton" value="Click" />
<script src="Scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#thisbutton").click(function () { $("#thetext").html("meow meow"); });
});
</script>
</body>
</html>
答案 2 :(得分:0)
如果要替换完整的div,请尝试replaceWith()jquery函数
$("#thetext").replaceWith("htmldata");