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

编程入门 行业动态 更新时间:2024-10-24 08:30:19
本文介绍了关闭对话框时如何清除对话框中的表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

点击按钮后,会添加2组数据。我使用材料设计。

按钮需要2次点击才能第一次运行功能。由于这一点,数据被添加到表2次。

代码

HTML

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

JS

function popup(listid){ var starCountRef = firebase.database()。ref('Orders /'+ listid).child('foodItems'); starCountRef.on('child_added',snapshot => { var snaps = snapshot.val(); var itemPrice = snaps.price; var itemName = snaps.productName; var itemQuantity = snaps.quantity; $ b console.log(itemName); $(#producttable)。append( '< td class =mdl-data-table__cell - non-numeric>'+ itemName + '< / td>< td>'+ itemQuantity +'< td>< td>'+ itemPrice +'< / td>< / tr>'); }); var dialog = document.querySelector('dialog'); var showDialogBu​​tton = document.querySelector('#dialog'); if(!dialog.showModal){ dialogPolyfill.registerDialog(dialog); showDialogBu​​tton.addEventListener('click',function(){ dialog.showModal(); }); dialog.querySelector('。close')。addEventListener('click',function(){ var element = document.getElementById(producttable) while(element .lastChild){ element.removeChild(element.lastChild); } dialog.close(); });

解决方案

工作:

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

根据需要添加。

When the button is clicked, 2 sets data is added. I use material design.

Button needs 2 clicks to run function for first time. Due to this, the data is added to table 2 times.

Code

HTML

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

JS

function popup(listid) { var starCountRef = firebase.database().ref('Orders/' + listid).child('foodItems'); starCountRef.on('child_added', snapshot => { var snaps = snapshot.val(); var itemPrice = snaps.price; var itemName = snaps.productName; var itemQuantity = snaps.quantity; console.log(itemName); $("#producttable").append( '<tr><td class="mdl-data-table__cell--non-numeric">' + itemName + '</td><td>' + itemQuantity + '</td><td>' + itemPrice + '</td></tr>' ); }); var dialog = document.querySelector('dialog'); var showDialogButton = document.querySelector('#dialog'); if (!dialog.showModal) { dialogPolyfill.registerDialog(dialog); } showDialogButton.addEventListener('click', function() { dialog.showModal(); }); dialog.querySelector('.close').addEventListener('click', function() { var element = document.getElementById("producttable") while (element.lastChild) { element.removeChild(element.lastChild); } dialog.close(); }); }

解决方案

This should work:

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

Add this as necessary.

更多推荐

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

本文发布于:2023-11-06 13:35:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563831.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对话框   表格   对话框中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!