好吧,我在同一个列表项中显示两个文本值时遇到问题(一,一
)这可能吗?
我正在尝试创建一个简单的日记/日志应用程序,您可以在其中添加标题(可选)和帖子条目本身的内容,按提交并让它创建一个显示内容的列表项.
HTML:
WriteUp Start Writing
JS:
//js to add text entries var ul = document.getElementById('list'), removeAll = document.getElementById('removeAll'), add = document.getElementById('add'); //make something happen when clicking on 'submit' add.onclick = function(){ addLi(ul); document.getElementById("titleHead"); }; //function for adding items function addLi(targetUl){ var inputText = document.getElementById('entry').value, li = document.createElement('li'), textNode = document.createTextNode(inputText + ''), removeButton = document.createElement('button'); if (inputText.split(' ').join(' ').length === 0) { //check for empty inputs alert ('No input'); return false; } removeButton.className = 'removeMe'; //add class to button for CSS removeButton.innerHTML = 'Remove'; //add text to the remove button removeButton.setAttribute('onclick', 'removeMe(this);'); li.appendChild(textNode); li.appendChild(removeButton); targetUl.appendChild(li); } //function to remove entries function removeMe(item){ var parent = item.parentElement; parent.parentElement.removeChild(parent); } removeAll.onclick = function(){ ul.innerHTML = ''; };
演示:http://codepen.io/Zancrash/pen/rxMxxQ(忽略角度登录的东西)