我正在嘗試做的是創(chuàng)建一個用戶下拉列表(選項)當用戶從下拉菜單中選擇選項時,它將在文本區(qū)域顯示其內(nèi)容/注釋<Option id="1"> Cancel </option><Option id="2"> Renew </option> <P><div id="1"> this is content of cancellation</p></div>因此,當用戶選擇“取消”時,它將在文本區(qū)域或“文字記錄”區(qū)域中顯示其內(nèi)容
2 回答

開心每一天1111
TA貢獻1836條經(jīng)驗 獲得超13個贊
請收聽變化select然后設置textContent的div:
document.getElementById("select").addEventListener("change", () => {
document.getElementById("myDiv").textContent = document.getElementById("select").value;
});
<select id="select">
<option id="1" value="Cancel"> Cancel </option>
<option id="2" value="Renew"> Renew </option>
</select>
<div id="myDiv">Replacement Text</div>
- 2 回答
- 0 關(guān)注
- 307 瀏覽
添加回答
舉報
0/150
提交
取消