button.value不会更改按钮的文本值

时间:2017-02-10 14:44:50

标签: javascript html object

我在javascript中有这段代码。它创建按钮并具有onclick功能,但.value不起作用

var button = document.createElement("button");
button.value = "+";
button.onclick = addBox;
document.getElementById("section").appendChild(button);

1 个答案:

答案 0 :(得分:1)

不是#with raw strings shutil.copy2(r"C:\Users\joaop\Desktop\VanillaServer\world",r"C:\Users\joaop\Desktop\VanillaServer\Backups") for filename in os.listdir(r"C:\Users\joaop\Desktop\VanillaServer\Backups"): if filename == world: os.rename(filename, "Backup " + date) #with double slashes shutil.copy2("C:\\Users\\joaop\\Desktop\\VanillaServer\\world","C:\\Users\\joaop\\Desktop\\VanillaServer\\Backups") for filename in os.listdir("C:\\Users\\joaop\\Desktop\\VanillaServer\\Backups"): if filename == world: os.rename(filename, "Backup " + date) 而是value。如果您使用值,则需要使用textContent<input type="button" />的文字位于Button

为什么textContent而不是textContent,因为innerHTML更快,它不会尝试解析为textContent

&#13;
&#13;
html
&#13;
var button = document.createElement("button");
button.textContent = "+";
document.getElementById("section").appendChild(button);
&#13;
&#13;
&#13;

对于输入,使用type = button

&#13;
&#13;
<div id="section">
  
</div>
&#13;
var button = document.createElement("input");
button.type = "button"
button.value = "+";
document.getElementById("section").appendChild(button);
&#13;
&#13;
&#13;