超开心
只能添加姓名
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body>请输入姓名<input type="text"> 请输入邮箱<input type="text"><ul></ul><button>添加</button><script>var btn = document.querySelector('button');var text = document.querySelectorAll('input');var ul = document.querySelector('ul');console.log(text);btn.onclick = function() {if (text.value == '') {return false;} else {var li = document.createElement('li');/* console.log(text.value); *//* li.innerHTML = text[0].value;li.innerHTML = text[1].value; *//* console.log(text[1].value) */for (i = 0; i <= text.length - 1; i++) {console.log(text[i].value);/* var ele = text[i].valueconsole.log(ele[i]); */ul.appendChild(li);li.innerHTML += text[i].value}}}</script>
</body></html>
解决