【问题标题】:Jquery Chosen - destroy method is not workingJquery Chosen - 销毁方法不起作用
【发布时间】:2019-01-26 05:07:21
【问题描述】:

我在使用 jQuery Chosen 插件的表单中有一堆选择元素。我无法重置表单:

我已引用此链接,但对我没有任何帮助:

jQuery Chosen reset

我的代码是:

 $scope.share = function (share_data,type, doc_type) {
        // $('.userlist').chosen().destroy()
            $scope.sharedgroup = [];
            $scope.users_select = "";
            // $scope.sharetype = type;
            $scope.doc_type = doc_type; 
            $scope.shareid = share_data._id;
            console.log(share_data)
            $('#shareModal').modal('toggle');
        $scope.getclientshare(share_data);  
        // $(".userlist").val([]).trigger('chosen:updated')
        $scope.getfilterlist=function(){
         $http.post("/getuserslist", { 'users': 'list'}).then(function (response) {
            $scope.userlist = response.data
            $(".userlist").val('').trigger("chosen:updated");
            $timeout(function () {
               $(".userlist").chosen({ disable_search_threshold: 3 });
                $scope.page_loader = false;            
          });

         });  
        }
        $scope.getfilterlist();


    };

是不是我做错了什么?

【问题讨论】:

  • 您希望destroy 做什么? 删除选中的元素?在那种情况下,我希望 $('.userlist').chosen().destroy() 能够工作(我不知道 Chosen 插件,但这是一个类似 jQuery 的流畅语法应该如何操作)。
  • destroy 会删除选中的那个。 $('.userlist').chosen().destroy() am getting is not a function 。 harvesthq.github.io/chosen

标签: jquery html jquery-chosen


【解决方案1】:

$(".chosen-select").val('').trigger("chosen:updated");

请试试这个,它会在你的下拉菜单中设置一个默认值。

【讨论】:

  • 你选择的 jquery 版本是什么?
  • $(".chzn-select").val('').trigger("liszt:updated");试试这个
  • v1.8.7 @shubham
  • 但 1 秒后隐藏
  • 什么是隐藏默认值或下拉菜单?
【解决方案2】:
 $(".userlist").html('').chosen();

【讨论】:

  • 感谢您的回复。但它完全使下拉列表清空.. 而不是删除选定的
  • 请尝试$(".userlist").val('').chosen();
  • 再试一次$(".chzn-select").val('').trigger("change");$(".chzn-select").val('').trigger("update");
【解决方案3】:

见下面的代码

 $(".chzn-select").chosen();
$('a').click(function(){
    $(".chzn-select").val('').trigger("liszt:updated");
});​

【讨论】:

  • 虽然此代码可能会解决问题,including an explanation 关于如何以及为什么解决问题将真正有助于提高您的帖子质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人。请edit您的回答添加解释并说明适用的限制和假设。
猜你喜欢
  • 2021-10-13
  • 2018-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多