<del id="d4fwx"><form id="d4fwx"></form></del>
      <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

            <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
          • jQuery中如何實現(xiàn)Chosen通用初始化

            小編給大家分享一下jQuery中如何實現(xiàn)Chosen通用初始化,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

            許昌網站建設公司創(chuàng)新互聯(lián)建站,許昌網站設計制作,有大型網站制作公司豐富經驗。已為許昌近1000家提供企業(yè)網站建設服務。企業(yè)網站搭建\外貿營銷網站建設要多少錢,請找那個售后服務好的許昌做網站的公司定做!

            no_results_text:"xxxxx"無搜索結果時顯示的文本

            allow_single_deselect:true 是否允許取消選擇
            disable_search: true 是否有搜索框出現(xiàn)

            max_selected_options:當select為多選時,最多選擇個數(shù)

            配置選項的官方說明文檔地址

            /* 功能: Chosen通用初始化
             * 創(chuàng)建人:Brian 創(chuàng)建時間:2016-12-13
             */
            (function ($j) {
              var chosenTool = function (el, options) {
                this.opts = options;
                this.chosenInit();
                this.chose_get_init();
                this.chose_mult_set_init(this.opts.hidClassName);
                this.clickEvent();
                return this;
              }
              chosenTool.opts = {
                selectId: '',//selectId
                hidClassName: '',//隱藏域Class
                placeholdertxt: '',//select中placeholder文字
                noresulttxt: '',//輸入的名稱未查到時顯示的文字
                dataJson: ''//數(shù)據(jù)源
              };
              $j.fn.myChosenTool = function (opt) {
                var value,
                  args = Array.prototype.slice.call(arguments, 1);
                var $jthis = $j(this),
                  data = $jthis.data('chosenTool'),
                  options = $j.extend({}, chosenTool.opts, $jthis.data(),
                    typeof option === 'object' && option);
                if (typeof option === 'string') {
                  //判斷用戶調用的方法是否存在
                  //if ($j.inArray(option, allowedMethods) < 0) {
                  //  throw new Error("Unknown method: " + option);
                  //}
                  if (!data) {
                    return;
                  }
                  value = data[option].apply(data, args);
                  if (option === 'destroy') {
                    $jthis.removeData('chosenTool');
                  }
                }
                /*插件外部調用插件內部的方法需要修改成下面形式*/
                //if (typeof opt === 'string') {
                //  if (!data) {
                //    return;
                //  }
                //  value = data[opt].apply(data, args);
                //  if (opt === 'destroy') {
                //    $jthis.removeData('chosenTool');
                //  }
                //}
                if (!data) {
                  opt["selectId"] = $j(this).attr("id");
                  $jthis.data('chosenTool', (data = new chosenTool(this, opt)));
                }
                console.log(data);
                return typeof value === 'undefined' ? this : value;
              };
              chosenTool.prototype.clickEvent = function () {
                var _this = this;
                $j("#" + this.opts.selectId).on("change", function () {
                  _this.chose_get_value();
                });
              };
              /*下拉框初始化方法*/
              chosenTool.prototype.selectInfoInit = function () {
                var proOPts = "";
                this.opts.dataJson = $j.parseJSON(this.opts.dataJson);
                $j.each(this.opts.dataJson, function (index, item) {
                  proOPts += "<option value='" + item.ValueField + "'>" + item.TextField + "</option>";
                });
                $j("#" + this.opts.selectId).append(proOPts);
                //初始化chosen
                $j("#" + this.opts.selectId).chosen({
                  allow_single_deselect: true, //是否允許取消選擇
                  placeholder_text_multiple: this.opts.placeholdertxt, //多選框沒有選中任何值的時候 顯示的文字
                  no_results_text: this.opts.noresulttxt,//無搜索結果時顯示的文本
                  search_contains: true//是否支持模糊搜索
                });
              };
              /*對象初始化方法*/
              chosenTool.prototype.chosenInit = function () {
                this.selectInfoInit();
              };
              //私有方法,檢測參數(shù)是否合法
              chosenTool.prototype.isValid = function () {
                return !this.options || (this.options && typeof this.options === "object") ? true : false;
              };
              //數(shù)據(jù)同步
              chosenTool.prototype.chose_get_init = function () {
                var selectId = this.opts.selectId;
                $j("#" + this.opts.selectId).chosen().change(
                     function () {
                       $j("#" + selectId).trigger("liszt:updated");//更新下拉框
                     });
              };
              //單選select value獲取
              chosenTool.prototype.chose_get_value = function () {
                var selectVal = $j("#" + this.opts.selectId).val();
                $j("." + this.opts.hidClassName).val(selectVal);
              };
              //單選select value獲取
              chosenTool.prototype.chose_mult_set_init = function () {
                var values = $j("." + this.opts.hidClassName).val();
                if (values && values.indexOf(',') > 0) {
                  var arr = values.split(',');
                  var length = arr.length;
                  var value = '';
                  for (i = 0; i < length; i++) {
                    value = arr[i];
                    $j("#" + this.opts.selectId + " [value='" + value + "']").attr('selected', 'selected');
                  }
                } else {
                  $j("#" + this.opts.selectId + " [value='" + values + "']").attr('selected', 'selected');
                }
                $j("#" + this.opts.selectId).trigger("liszt:updated");
              };
              //select text獲取,多選時請注意
              chosenTool.prototype.chose_get_text = function () {
                return $j("#" + this.opts.selectId + " option:selected").text();
              };
            })(jQuery);

            以上是“jQuery中如何實現(xiàn)Chosen通用初始化”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

            網頁名稱:jQuery中如何實現(xiàn)Chosen通用初始化
            轉載來于:http://www.jbt999.com/article22/jisjcc.html

            成都網站建設公司_創(chuàng)新互聯(lián),為您提供企業(yè)網站制作App開發(fā)、做網站、微信公眾號、動態(tài)網站網站導航

            廣告

            聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

            微信小程序開發(fā)

              <del id="d4fwx"><form id="d4fwx"></form></del>
              <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

                    <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
                  • 北条麻妃一级婬片A片 | 日韩有码一区 | 国产天天操女人 | 91一区论坛 | 色爱五月天 |