[英]How to move text from one place to another
Here is the code block I created to make my to do list (this code is kept inside of a javascript library) 这是我创建的待办事项列表代码块(此代码保留在javascript库中)
function addItem() {
var newItem = document.createElement("div");
newItem.innerHTML = document.getElementById("box").value;
newItem.onclick = removeItem;
document.getElementById("list").appendChild(newItem);
saveList();
}
function saveList() {
localStorage.storedList = document.getElementById("list").innerHTML;
}
function loadList() {
document.getElementById("list").innerHTML = localStorage.storedList;
for(var i = 0; i < list.children.length; i++) {
list.children[i].onclick = removeItem;
}
}
This code is not kept inside of a javascript library. 此代码未保存在javascript库中。
<script>
function removeItem() { confirm("Mark task as completed?"); saveList(); }
</script>
<input type="text" id="box" placeholder="Type here to add task"
onKeyDown="if(event.keyCode==13) addItem();"/> <br/>
<button class="button" onclick="addItem();" style="float left;">
<span>Add task</span>
</button> <br/><br/><br/>
<div class="title">
<strong>Tasks:</strong>
</div>
<div class="noselect">
<p>____________________________________________________</p>
</div><br/>
<div id="list"></div>
<div class="noselect">
<p>____________________________________________________</p>
</div><br/><br/>
<div class="title">
<strong>Completed:</strong>
</div>
<div class="noselect">
<p>____________________________________________________</p>
</div><br/>
<div id="list2"></div>
<div class="noselect">
<p>____________________________________________________</p>
</div>
What I want to happen is when they click on the task and agree to mark it as completed, I want it to be removed from list1 and be added to list2. 我要发生的是,当他们单击任务并同意将其标记为已完成时,我希望将其从list1中删除并添加到list2中。
Here is the link: https://aaronproductions.neocities.org/To_Do_List.html 这是链接: https : //aaronproductions.neocities.org/To_Do_List.html
This is NOT a duplicate because the possible duplicates solution does NOT fix my problem. 这不是重复项,因为可能的重复项解决方案无法解决我的问题。
You could do the following 您可以执行以下操作
function onclickHandler(event){
var target = event.target || event.srcElement;
var targetValue = target.innerText;
addItem(targetValue, document.getElementById('list2');
target.parentNode.removeChile(target);
}
function addItem(value, list){
var newItem = createElement(value);
list.appendChild(newItem);
}
function createElement(value){
var item = document.createElement('div');
item.innerText = value;
return item;
} }
The "onclickHandler" should be attached to every item in "list1" “ onclickHandler”应附加到“ list1”中的每个项目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.