Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jquery添加或删除动态元素?_Jquery - Fatal编程技术网

如何使用jquery添加或删除动态元素?

如何使用jquery添加或删除动态元素?,jquery,Jquery,此代码在添加包含来自ajax请求的数据的动态表时有效,但无法删除动态表。下面的代码显示,每当我单击树节点时,它都应该将其mysql表数据加载到HTML表中 $("#treeNodes").on("select_node.jstree", function(event, data) { var node = data.rslt.obj; var nodeID = node.attr("id"); event.st

此代码在添加包含来自ajax请求的数据的动态表时有效,但无法删除动态表。下面的代码显示,每当我单击树节点时,它都应该将其mysql表数据加载到HTML表中

     $("#treeNodes").on("select_node.jstree", function(event, data)
     {
           var node = data.rslt.obj;
           var nodeID = node.attr("id");
           event.stopImmediatePropagation;
           if(/leaf/.test(nodeID))
           {
                $(".tableData > *").remove(); // remove all table data (tr rows) before adding the new data and not working or firing off.
                addTableData(); // This function get the data from a mysql table and loads it into an HTML table.
           }

     });

     <table>
            <tbody class='tableData'></tbody>
    </table>
$(“#treeNodes”)。在(“select_node.jstree”,函数(事件,数据)
{
var节点=data.rslt.obj;
var nodeID=node.attr(“id”);
事件。停止即时传播;
if(/leaf/.test(nodeID))
{
$(“.tableData>*”).remove();//在添加新数据且不工作或触发之前,请删除所有表数据(tr行)。
addTableData();//此函数从mysql表获取数据并将其加载到HTML表中。
}
});
有人能告诉我这段代码如何识别新添加的动态表数据,以便将其删除吗?

这应该可以:

$(".tableData").html("");
但是anOG写的更快。因此,请改用
empty()

试试以下方法:

$('.tableData').empty();

empty(),它是有效的。我必须升级到一个父级,它使用表id而不是tbody id工作