简体   繁体   English

如何将文字从一个地方移到另一个地方

[英]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.

相关问题 如何将文本从一页移到另一页的形式 - How to move text from one page into the form of another page 如何使用纯JavaScript在DOM中将元素从一个地方移动到另一个地方? - How to move an element from one place to another in the DOM using plain JavaScript? 如何将节点从一个模拟移动到另一个模拟 - How to move a node from one simulation to another 如何将元素从一个列表移动到另一个列表 - How to move elements from one list to another 如何将一个项目从一个列表移动到另一个列表? - How to move an item from one list to another? Javascript-在上一个文本框填充后,如何将焦点从Javascript中的一个文本框移到另一个文本框? - Javascript - How to move focus from one textbox to another in Javascript after the previous text box is filled? 使用javascript或mootools将文本从一个div移动到另一个 - move text from one div to another with javascript or mootools 将所选对象从一个位置移到另一位置,然后再次移回原始位置 - Move selected objects from one place to another and back again to original position javascript Angular 2操纵DOM - 在保留功能的同时将组件从一个地方移动到另一个地方 - Angular 2 manipulate DOM - move component from one place to another while preserving functions 对数组进行排序以将元素从一个位置移动到另一个位置,同时保持“order”字段相同 - Sorting an array in order to move an element from one place to another, while keeping `order` field the same
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM