关闭对话框时如何清除对话框中的表

时间:2018-04-07 13:06:30

标签: javascript html

单击该按钮时,会添加2组数据。我使用材料设计。

按钮需要2次点击才能第一次运行功能。因此,数据将被添加到表中2次。

代码

HTML

() => 5 > 3

JS

<button onclick="purchaseList(orderid)" id="dialog">Button</button>

3 个答案:

答案 0 :(得分:1)

这应该有效:

var element = document.getElementById("producttable")
while (element.lastChild) {
    element.removeChild(element.lastChild);
}

根据需要添加。

答案 1 :(得分:1)

我建议您将firebase功能从使用.on更改为.once,以避免向您的表中多次添加数据,并且由于您的数据不会经常更改或需要主动监听,因此您最好使用.once以获得性能优势。

firebase.database().ref('Orders/' + 
    listid + '/foodItems').once('value').then(function(snapshot) {
            // the rest of your code goes here
});

答案 2 :(得分:0)

这个带有类名&#34; .mdl-data-table__cell--non-numeric&#34;的remocve元素 当用户点击.close

dialog.querySelector('.close').addEventListener('click', function () {

    dialog.close();
         $(".mdl-data-table__cell--non-numeric").remove();
});

更新:

打开对话框,第二次单击使用伪元素激活,如下所示

<div class=pseudo><button onclick="purchaseList(orderid)"id="dialog" disabled>Button</button></div>
var i=0;
$('.pseudo').click(function(){
 i++;
  if(i==2){
   $("#dialog").prop('disabled',false);
 }
});
相关问题