[英]How to set the li value (text inside the li) in the input filed in TODO application when user click on update button?
下面是我的代碼,實際上我想在用戶單擊更新按鈕時將 li 文本設置到輸入字段中。 當用戶單擊更新按鈕時,代碼正在工作輸入元素顯示,但 li 標簽中的值未顯示在輸入字段中,但顯示在控制台中我還附上了圖片以在替換輸入時清除它帶按鈕
[function addTodo() {
// create li
var todo_input = document.getElementById('todo-input');
var li = document.createElement('li');
var textNode = document.createTextNode(todo_input.value);
li.setAttribute('class', 'li');
li.appendChild(textNode);
// create update button
var updateBtn = document.createElement('button');
var updateText = document.createTextNode('UPDATE');
li.appendChild(updateBtn);
li.appendChild(deleteBtn);
addList.appendChild(li);
}
function updateItem(e) {
var val1 = e.parentNode.firstChild;
var inputVal = document.createElement('input');
inputVal.setAttribute('class','todo-input');
inputVal.setAttribute('type','text');
var textNode = document.createTextNode(val1.nodeValue);
inputVal.appendChild(textNode);
}][1]
不要 append 輸入框中的文字。 使用值屬性。
inputVal.value = val1.nodeValue;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.