이 소용돌이를 부여 참조하십시오 (당신이 jQuery를 사용할 수 있다면이 훨씬 간단 할 것 명심하십시오 printhere
DIV에 li
의 텍스트를 추가 :
http://jsfiddle.net/79GQp/1/
<ul id="interperson">
<li>Critical and self-critical abilities</li>
<li>Teamwork</li>
<li>Interpersonal skills</li>
<li>Ability to work in an interdisciplinary team</li>
<li>Ability to communicate with experts in other fields</li>
<li>Appreciation of Diversity and multiculturality</li>
<li>Ability to work in an international context</li>
<li>Ethical commitment</li>
</ul>
<ul id="printhere"> </ul>
li
을 첨부하려고 했으므로 printhere
을 ul
으로 변경했습니다.
스크립트 : 비교를 들어
window.onload = function() {
document.getElementById("interperson").onclick = moveToPrint;
document.getElementById("printhere").onclick = removeItem;
};
function checkElementType(node, type) {
return node.nodeName.toLowerCase() === type.toLowerCase();
}
function checkForDupe(testNode, dest) {
var existing = dest.getElementsByTagName("li"), i;
for (i = 0; i < existing.length; i += 1) {
if (existing[i].textContent === testNode.textContent) {
return true;
}
}
return false;
}
function moveToPrint(event) {
var targ = event.target,
ph = document.getElementById("printhere");
if (checkElementType(targ, "li")) {
if (checkForDupe(targ, ph)) {
alert("That item has already been added!");
return;
}
ph.appendChild(targ.cloneNode(true));
}
}
function removeItem(event) {
var targ = event.target;
if (checkElementType(targ, "li")) {
targ.parentNode.removeChild(targ);
}
};
, 여기가 jQuery를 함께 할 수있는 방법은 다음과 같습니다 여기
http://jsfiddle.net/79GQp/3/
$(function() {
$("#interperson").on("click", "li", moveToPrint);
$("#printhere").on("click", "li", function() {
$(this).remove();
});
});
function moveToPrint() {
var targ = $(this),
ph = $("#printhere"),
matchingItems = ph.children("li").filter(function() {
return this.textContent === targ.text();
});
if (matchingItems.length > 0) {
alert("That item has already been added!");
return;
}
ph.append(targ.clone());
}
리에 고유 한 ID를 추가 할 수 있습니까? – Chausser
JavaScript가 어떻게 "고장 났는지"에 관계없이 시도를 게시 할 수 있습니까? 문제 및/또는 JS 언어에 대해 이해하지 못하는 것에 대한 통찰력을 제공 할 수 있습니다. – ajp15243
함수 addinterpersonal() { \t var myinter = document.getElementById ("interperson"). 값; \t var printlist = document.getElementById ("selected"); \t printlist.innerHTML + = "