javascript - 添加删除列表问题
巴扎黑
巴扎黑 2017-04-11 11:42:43
0
2
503

程序主要意思是输入框输入水果名称,原来列表删除相应的节点,把这种水果添加到另一个列表中
写的程序可以实现,但是后台报错,1.html:61 Uncaught TypeError: Cannot read property 'cloneNode' of undefined
html。。。导致后面的输入框清空语句没法执行,求帮忙 新手

<ul class='cls1'>fruit</ul>
<ul class='cls2'>basket</ul>
<input type="text" id='in' name="test"/>
<input id='check' type='submit'  value='submit' name='btn'/>

JS

  window.onload=function(){
     window.onload=function(){
      var arr=['mango','apple','grape','watermelon'];
         var list="";
         for(var k=0;k<arr.length;k++){
             list+='<li>'+arr[k]+'</li>'
          document.querySelector('.cls1').innerHTML=list;
         }
         var check=document.getElementById('check');
         var list1 =document.querySelector('.cls1');
           check.addEventListener("click",function(){
                var content=document.getElementById('in').value;
                var list2 =document.querySelector('.cls2');
                var aLi=document.getElementsByTagName('li');
                for(var i=0;i<aLi.length;i++){
                 if(content==aLi[i].innerText){
                       list2.appendChild(list1.children[i].cloneNode(true));
                       list1.removeChild(list1.children[i]);
                 }
                }
                document.getElementById("in").value="";
           })
 
 }
巴扎黑
巴扎黑

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!