![](/img/trans.png)
[英]How to add li elements to ul using JavaScript when clicking submit button
[英]Using javascript: How do I add to text when clicking the submit button
我對javascript很陌生,在開發的應用程序中列出“待辦事項”列表時遇到很大的麻煩。 目前,您可以在文本字段中輸入內容,然后單擊提交,這將顯示您鍵入的內容以及旁邊的復選框。 一切都很好,但是如果我添加其他任何方法來做,那么之前的文本和復選框將被覆蓋,並且我不知道如何添加到列表中。
任何幫助將不勝感激!
HTML:
Enter What To Do <input id='userInput' size=60>
<button onClick='userSubmit()'>Submit</button>
<BR><P>
<div id='result'></div>
JS:
function userSubmit() {
var UI=document.getElementById('userInput').value;
document.getElementById('result').innerHTML='<input type="checkbox">' + UI;
}
嘗試這個:
document.getElementById('result').innerHTML+='<input type="checkbox"> '+UI+'<br>';
<script type='text/javascript'>
function userSubmit() {
var UI=document.getElementById('userInput').value;
document.getElementById('result').appendChild('<p><input type="checkbox"> '+UI+'</input></p>);
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.