无法读取属性:空值样式

时间:2019-11-24 14:42:11

标签: javascript

我正在使用Vanilla Javascript开发Trello板,并且在制作Cards时收到错误消息。我已经使用本地存储和会话存储分别存储卡和列表,但是我无法弄清楚为什么在单击“添加卡板”按钮后此错误仍然存​​在


function newTask(x){
        card_index= parseInt(localStorage.getItem("card_indices")) ;
        //card_index = parseInt(sessionStorage.getItem("card_indices"));
        list_index = parseInt(sessionStorage.getItem("index"));
        document.getElementById('myTasks').innerHTML +=
        '<div id = "list_' + list_index + ' " class="list-item animated zoomIn" > <h2 id = "title_' + list_index +'" onClick = "modifyObj.titleEdit('+ list_index +')" class="list-item__h2">'+x+'</h2><span id = "span_del_' + list_index + '" class ="btn title-delete" onClick ="modifyObj.titleDelete(' + list_index + ')">\u00D7</span><hr>'+
        '<input  id = "card_del_' + card_index + '" type="text" class="myInput" placeholder="Title...">' +
        '<div class="btn add-items " id = "div_add_list_"  onClick = "myCard.titleForm(' + list_index + ',' + card_index + ')" >Add List Item</div>'
        '</div>'
        sessionStorage.setItem("index", parseInt(sessionStorage.getItem("index"))+1);

    }




var myCard = {

         card:function(index, card_index){


             var enteredElement = document.getElementById('card_del_' + card_index).value;

             var textNode = document.getElementsByClassName('text_' + card_index);


                    textNode.innerText = enteredElement;


             if (enteredElement === ""){
                 alert("You must write something ");
                 }
             else{
                  document.getElementById("text_").style.display = "block";

                 }
         },


   titleForm: function(index,card_index){
       element = document.getElementById('card_del_' + card_index);

       text = '<li style="display:none" class="text_'+ card_index +'"> <span class = "btn items" onClick = "myCard.cardClose()">u00D7</span></li>'

       element.insertAdjacentHTML('beforeend', text);
        myCard.card(index,card_index);         
           localStorage.setItem("card_indices", parseInt(localStorage.getItem("card_indices"))+1); 
             // card_index+=1;

    }};

0 个答案:

没有答案