【发布时间】:2017-06-03 23:04:59
【问题描述】:
基本上,我想做的是:
当你按下button#change时,div#board中的内容必须改为:
<h2>Hi!</h2>
<button type="button" onclick="ChangeAgain();">
然后当你点击那个button时,它必须变回原来的样子,即:
<h2>Welcome to this page.</h2>
<p>It's quite boring in here. Why don't you click the button?</p>
<button onClick="Change();">Button for you to Click</button>
这是我的 JavaScript (jQuery 3.2.1),它不起作用。
$(function () {
var inThere = "";
function Change() {
inThere += $("#board").html();
$("#board").html("<h2>Hi!</h2> \n
<button type=\"button\" onclick=\"ChangeAgain();\">")
}
function ChangeAgain () {
$("#board").html(inThere);
}
})
【问题讨论】:
-
不要将它们包装在文档就绪处理程序中
-
@Satpal 你能详细说明一下答案吗?
标签: javascript jquery html dom-manipulation