2 回答

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超13個(gè)贊
你可以這樣做:
const submitFunc = () => {
const value = document.getElementById('name').value;
const parent = document.createElement('div');
const pTag = document.createElement('p');
pTag.innerText = value;
parent.appendChild(pTag);
document.body.appendChild(parent);
}
<button onclick="submitFunc()">Submit</button>
<input placeholder="Enter Name Here" id="name">

TA貢獻(xiàn)1858條經(jīng)驗(yàn) 獲得超8個(gè)贊
如果你想將其顯示為 H1 元素,你可以執(zhí)行以下操作
const submitFunc = () => {
const value = document.getElementById('name').value;
const parent = document.createElement('div');
const hTag = document.createElement('h1');
var node = document.createTextNode(value);
hTag.appendChild(node);
parent.appendChild(pTag);
document.body.appendChild(parent);
}
這是要使用的標(biāo)記。
<button onclick="submitFunc()">Submit</button>
<input placeholder="Enter Name Here" id="name">
- 2 回答
- 0 關(guān)注
- 142 瀏覽
添加回答
舉報(bào)