私はこのコードをジャバスクリプトに持っています。これは、ボタンを作成し、onclickの機能を持っていますが、.VALUEはbutton.valueはボタンのテキスト値を変更していません
var button = document.createElement("button");
button.value = "+";
button.onclick = addBox;
document.getElementById("section").appendChild(button);
私はこのコードをジャバスクリプトに持っています。これは、ボタンを作成し、onclickの機能を持っていますが、.VALUEはbutton.valueはボタンのテキスト値を変更していません
var button = document.createElement("button");
button.value = "+";
button.onclick = addBox;
document.getElementById("section").appendChild(button);
ないvalue
しかしtextContent
動作しません。値を使用する場合は、<input type="button" />
を使用する必要があります。 Button
のテキストはtextContent
です。
なぜtextContent
であり、innerHTML
でないと、textContent
が高速であるため、html
に解析しようとしません。タイプと入力の場合
var button = document.createElement("button");
button.textContent = "+";
document.getElementById("section").appendChild(button);
<div id="section">
</div>
=ボタン
var button = document.createElement("input");
button.type = "button"
button.value = "+";
document.getElementById("section").appendChild(button);
<div id="section">
</div>
.i-i-n-n-e-r-T-e-x-t- '.textContent'を使用することもできます。 '.value'はボタン上で有効ですが、テキストとして表示されません。 – evolutionxbox
もっと "正しく": 'button.appendChild(document.createTextNode(" + "));' –
@evolutionxbox 'innerText'は古いIEだけです。あなたは 'textContent'を望みます。 –
は、あなたが "' .value'は動作しません" によって何を意味するか追加することができます?あなたは何を期待していますか? – evolutionxbox
'addBox'関数も表示できますか? –
ようこそStackOverflow!あなたの質問に精通してください。何かが「うまくいきません」と言っているのは、他のユーザーが正しい答えを提供するのに十分なほどの記述ではありません。あなたは何を達成しようとしていますか?何を試しましたか? –