0

如何确保点击事件只点击一次而不是多次在jstree中创建多个叶子节点?单击文件按钮时,下面的代码有时会创建多个叶节点

这是代码:

        $(".hoverTree").hover(function()
        {
              $(this).on("click", function(event)
              {
                   if($.trim($(this).attr("value")) == "fileButton")
                   {
                       var fileID = setID();
                       $("#treeFile").jstree("create", null, "last", {"attr" : "SpecialFile", "id" : "file_"+fileID})
                   }
              });
        });
4

1 回答 1

1

您可以使用.one()

$(this).one("click", function(event)
          {
               if($.trim($(this).attr("value")) == "fileButton")
               {
                   var fileID = setID();
                   $("#treeFile").jstree("create", null, "last", {"attr" : "SpecialFile", "id" : "file_"+fileID})
               }
          });
于 2013-06-26T18:32:13.230 回答