0
我想让我的代码使用函数删除一个新的div。删除创建的Div
JavaScript可以添加一个新的div没有任何问题。但删除按钮不响应。
如何让我的JavaScript删除div。
脚本:
\t <script async> // hidden answer for adding new answers jacascript code
\t \t \t function clonebutton1 (counter){
\t \t \t \t counter = counter +1;
\t \t \t \t var div = document.createElement('div');
\t \t \t \t div.className = 'container-fluid form-group col-lg-6';
\t \t \t \t div.innerHTML ='<label>Answer:\
\t \t \t <span id="ansNo">'+counter+'</span>\
\t \t \t </label> \
\t \t \t <input class="form-control" id="AnswerClone" name="quizAnswerNew[]" placeholder="Please Enter An Answer......" type="text" value="">\
\t \t \t <div class="form-group">\
\t \t \t \t <label for="select1">Pick a Score For The Answer:</label> \
\t \t \t \t <select class="score-choice" id="selectClone" name="selectNew">\
\t \t \t \t <option selected value="0">0</option><option value="5">5</option><option>10</option><option>15</option><option>20</option>\
\t \t \t \t </select>\
\t \t \t </div>\
\t \t \t <div style="margin-bottom:20px;">\
\t \t \t \t <label class="btn-bs-file btn btn-sm btn-primary">Add Picture <input name="answerFileNew" type="file"></label>\
\t \t \t </div><input class="btn btn-primary removeAnswer" id="removeAnswer" type="button" value="Remove Answer">\
\t \t </div>';
\t
\t \t \t document.getElementById('AnswerSectionNew').appendChild(div);
\t \t \t \t \t div.on("click", function() {// this function removes the parent of the removeAnswer button that is clicked
\t \t \t \t \t \t \t \t \t $(this).parent().remove();
\t \t \t \t \t });
\t \t \t document.getElementById('addAnotherAnswer').setAttribute("onClick","clonebutton1("+counter+")");
\t };
\t \t \t
\t \t \t
\t
\t </script>
感谢