該代碼的用途是當單擊數組中的字母時,它們應顯示在文本框中。該陣列由字母組成,如鍵盤。我試過但我不知道我做錯了什麼。任何人都可以幫忙嗎?單擊時向文本框添加文本
<html>
<head>
<body>
<textarea id="Alltext"></textarea>
<div id = "playground">
</div>
</body>
<script>
var Item = function(name){
this.name = name;
var div = document.createElement("div");
div.className = "";
div.innerHTML = name;
this.div = div;
this.appendTo = function (parent){
parent.append(this.div);
}
this.setName = function(newName){
this.div.innerHTML = newName;
this.name = newName;
}
this.div.addEventListener('click', function(event){
//change the color of the item for 2 seconds
var clickedElement = event.target;
clickedElement.classList.add("clicked");
window.setTimeout(function(){
clickedElement.classList.remove("clicked");
});
});
}
var names = ["Q","W", "E", "R","T","Y", "U","I","O","P","A","S","D","F","G","H","J","K","L",];
var playground = document.getElementById("playground");
for(var i = 0; i < names.length; i++){
var myItem = new Item(names[i]);
myItem.appendTo(playground);
}
</script>
</html>
不知道什麼代碼,這部分是所有關於'變量一個=這一點;'看起來不像任何有效的JavaScript我有生以來看到。可能比這個更多的問題,但你需要解決這個問題。 – chairmanmow