我正在编码待办事项列表应用程序,但是javascript代码存在一些错误。所以问题是当李出现时,它是“未定义的”,有时甚至是空格HTML
<section>
<div class="list-app">
<ul id="list">
<li>Hell</li>
</ul>
<div class="bottom">
<input type="text" name="game" placeholder="Type Your List">
<img src="add.png" id="add">
<img src="trash.jpg" id="remove">
</div>
</div>
</section>
和javascript
var remove = document.querySelector('#remove');
var add = document.getElementById('add');
var textPlace = document.querySelector('input');
var listSingle = document.querySelector('LI');
var input = document.getElementsByName('game');
var items = [''];
add.addEventListener('click', function() {
items.push = [input.value];
document.getElementById('list').innerHTML = '<li>' + items + '</li>';
})
别介意其他代码,它只是添加按钮的对应版本
items变量是一个数组,您最初将一个空字符串添加为该数组中的第一项。
然后在onclick函数中,您引用该数组。引用是针对数组对象本身(而不是数组中的项目或所有数组项目的字符串)。