OK, mam problem z wyświetlaniem dwóch wartości tekstowych w obrębie tego samego elementu listy (jeden <input>
, jeden <textarea>
) Czy to możliwe?Tworzenie 2 wartości tekstowych w 1 pozycji listy
Próbuję utworzyć prostą aplikację dziennik/dziennik, w której można dodać tytuł (opcjonalnie) i treść samego wpisu, naciśnij przycisk prześlij i poproś o utworzenie elementu listy wyświetlającego treść.
HTML:
<html>
<head>
<title>WriteUp</title>
</head>
<body>
<div id="textWrap">
<div class="border">
<h1>Start Writing</h1><br />
<input id="title" placeholder="Title (Optional)">
<textarea rows="4" cols="50" type="text" id="entry" maxlength="500" placeholder="Add stuff..."></textarea><br />
<button id="add">Submit</button>
<button id="removeAll">Remove All</button>
<ul id="list"></ul>
</div><!--end of border div-->
</div><!--end of textWrap-->
</body>
</html>
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 = '';
};
demo: http://codepen.io/Zancrash/pen/rxMxxQ (ignorować kątowe logowanie rzeczy)