`
x9x9x9x9
  • 浏览: 18832 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类

selectArray

阅读更多
var selectArray = new  Array();

/**
* ÈÃFlexÏÂÀ­¿òÑ¡ÖÐijһֵ
*/
function setFlexValue(selectId,value) {
        if(getFlexSelect(selectId)) {
                getFlexSelect(selectId).setValue(value);
                } else {
                        alert("ûÓÐÕÒµ½Ñ¡ÔñÏî");
                }
}
/**
* È¡FlexÏÂÀ­¿òÖµ
*/
function getFlexValue(selectId) {
        if(getFlexSelect(selectId)) {
        return  getFlexSelect(selectId).getValue();
                } else {
                        alert("ûÓÐÕÒµ½Ñ¡ÔñÏî");
                }
}
/**
* È¡FlexÏÂÀ­¿òÎı¾
*/
function getFlexText(selectId) {
        if(getFlexSelect(selectId)) {
        return  getFlexSelect(selectId).getText();
                } else {
                        alert("ûÓÐÕÒµ½Ñ¡ÔñÏî");
                }
}
/**
* FlexÏÂÀ­¿òÖµÔö¼ÓÒ»ÅúÑ¡Ïî
*/
function addFlexOptions(selectId,objArray) {
        if(this.selectArray!=undefined&&objArray!=undefined) {
                                for(var j=0;j<objArray.length;j++) {
                                                addOption(selectId,objArray[j].name,objArray[j].value);
                                        }
                }
}
/**
* Çå¿ÕFlexÏÂÀ­¿òËùÓÐÑ¡Ïî
*/
function emptyFlex(selectId) {
        if(getFlexSelect(selectId)) {
                getFlexSelect(selectId).removeOption();
                } else {
                        alert("ûÓÐÕÒµ½Ñ¡ÔñÏî");
                }
}
/**
* Çå¿ÕFlexÏÂÀ­¿òËùÓÐÑ¡Ïî²¢±£ÁôÒ»¸öĬÈÏoption
*/
function emptyFlexSetDefVal(selectId, def) {
        if(getFlexSelect(selectId)) {
                getFlexSelect(selectId).removeOption();
                addFlexOption(selectId,def['name'],def['value']) ;
                } else {
                        alert("ûÓÐÕÒµ½Ñ¡ÔñÏî");
                }
}
/**
* FlexÏÂÀ­¿òÖµÔö¼ÓÒ»¸öÑ¡Ïî
*/
function addFlexOption(selectId,name,value) {
        if(getFlexSelect(selectId)) {
                getFlexSelect(selectId).addOption(name,value);
                } else {
                        alert("ûÓÐÕÒµ½Ñ¡ÔñÏî");
                }
}
/**
* FlexÏÂÀ­¿ò½ûÓã¨Ö»½ûÓÃInput£¬Hidden±£Áô£©
*/
function setFlexDisabled(selectId) {
        if(getFlexSelect(selectId)) {
                getFlexSelect(selectId).disabled();
                } else {
                        alert("ûÓÐÕÒµ½Ñ¡ÔñÏî");
                }
}

function getFlexSelect(selectId) {
       
        if(this.selectArray!=undefined) {
                for(var i=0;i<selectArray.length;i++) {
                        if(selectArray[i].id==selectId) {
                        return  selectArray[i].selectObject;
                                }
                        }
                }
                return undefined;
        }
(function($) {
  $.flexselect = function(select, options) { this.init(select, options); };

  $.extend($.flexselect.prototype, {
    settings: {
      allowMismatch: false,
      selectedClass: "flexselect_selected",
      dropdownClass: "flexselect_dropdown",
      inputClass:"flexselect_input",
      inputIdTransform:    function(id)   { return id + "_flexselect"; },
      inputNameTransform:  function(name) { return; },
      dropdownIdTransform: function(id)   { return id + "_flexselect_dropdown"; }
    },
    select: null,
    input: null,
    hidden: null,
    dropdown: null,
    dropdownList: null,
    cache: [],
    results: [],
    lastAbbreviation: null,
    abbreviationBeforeFocus: null,
    selectedIndex: 0,
    picked: false,
    dropdownMouseover: false, // Workaround for poor IE behaviors
    inputMouseover: false,
                myevent : null,
    init: function(select, options) {
      $.extend(this.settings, options);
      this.select = $(select);
      this.preloadCache();
      this.renderControls();
      this.wire();
    },

    preloadCache: function() {
      this.cache = this.select.children("option").map(function() {
        return { name: $.trim($(this).text()), value: $(this).val(), score: 0.0 };
      });
    },
    renderControls: function() {
      var selected = this.select.children("option:selected");
                       
      this.hidden = $("<input type='hidden'/>").attr({
        id: this.select.attr("id"),
        name: this.select.attr("name")
      });
      this.hidden.val(selected.val());
      this.input = $("<input type='text' autocomplete='off' />").attr({
        id: this.settings.inputIdTransform(this.select.attr("id")),
        name: this.settings.inputNameTransform(this.select.attr("name")),
        accesskey: this.select.attr("accesskey"),
        tabindex: this.select.attr("tabindex"),
        style: this.select.attr("style")
      }).addClass(this.settings.inputClass)
      .bind('onchange1',this.select.attr("onchange")||function(){}).
      val($.trim(selected.text()));
  
                        this.myevent = $("<iframe style='z-index:-1;background-color: #E6E4E7; '  scrolling='no' frameborder='0'></iframe>");
      this.dropdown = $("<div style='height:150px;width:100% ;overflow-x:hidden; ' scrolling='no'></div>").attr({
        id: this.settings.dropdownIdTransform(this.select.attr("id"))
      }).addClass(this.settings.dropdownClass);
    this.dropdown.append(this.myevent);
      this.dropdownList = $("<ul></ul>");
                        this.dropdown.append(this.dropdownList);
                //      this.input.after($('<img class="button" src="dropdown.gif" />'));
     this.select.after(this.input).after(this.hidden).remove();
      $("body").append(this.dropdown);

    },
    wire: function() {
      var self = this;

      this.input.click(function() {
        self.lastAbbreviation = null;
        self.focus();
      });

      this.input.mouseup(function(event) {
        event.preventDefault();
      });

      this.input.focus(function() {
        self.abbreviationBeforeFocus = self.input.val();
        self.input.select();
        //if (!self.picked)
         self.filterResults(true);
      });

      this.input.blur(function() {
        if (!self.dropdownMouseover) {
          self.hide();
          if (!self.picked) self.reset();
        }
      });
      this.dropdownList.mouseover(function (event) {
        if (event.target.tagName == "LI") {
          var rows = self.dropdown.find("li");
          self.markSelected(rows.index($(event.target)));
        }
      });
      this.dropdownList.mouseleave(function () {
        self.markSelected(-1);
      });
      this.dropdownList.mouseup(function (event) {
        self.pickSelected();
        self.focusAndHide();
      });
      this.dropdown.mouseover(function (event) {
        self.dropdownMouseover = true;
      });
      this.dropdown.mouseleave(function (event) {
        self.dropdownMouseover = false;
        self.focusAndHide();
      });
      this.input.mouseover(function (event) {
        self.inputMouseover = true;
      });
      this.input.mouseleave(function (event) {
        self.inputMouseover = false;
      });     
      this.dropdown.mousedown(function (event) {
        event.preventDefault();
      });

      this.input.keyup(function(event) {
        switch (event.keyCode) {
          case 13: // return
            event.preventDefault();
            self.pickSelected();
            self.focusAndHide();
            break;
          case 27: // esc
            event.preventDefault();
            self.reset();
            self.focusAndHide();
            break;
          default:
            self.filterResults();
            break;
        }
      });

      this.input.keydown(function(event) {
        switch (event.keyCode) {
          case 9:  // tab
            self.pickSelected();
            self.hide();
            break;
          case 33: // pgup
            event.preventDefault();
            self.markFirst();
            break;
          case 34: // pgedown
            event.preventDefault();
            self.markLast();
            break;
          case 38: // up
            event.preventDefault();
            self.moveSelected(-1);
            break;
          case 40: // down
            event.preventDefault();
            self.moveSelected(1);
            break;
          case 13: // return
          case 27: // esc
            event.preventDefault();
            event.stopPropagation();
            break;
        }
      });
    },

    filterResults: function(focs) {
      var abbreviation = this.input.val();
      if (abbreviation == this.lastAbbreviation){return;}

      var results = [];
      $.each(this.cache, function() {
        this.score = LiquidMetal.score(this.name, abbreviation);
        if(focs) {
                 if (this.score >= 0.0) results.push(this);
                } else{
                         if (this.score > 0.0) results.push(this);
                        }
      
      });
      this.results = results;

      this.sortResults();
      this.renderDropdown();
      this.markFirst();
      this.lastAbbreviation = abbreviation;
      this.picked = false;
    },
    sortResults: function() {
      this.results.sort(function(a, b) { return b.score - a.score; });
    },

     renderDropdown: function() {
      var dropdownBorderWidth = this.dropdown.outerWidth() - this.dropdown.innerWidth();
      var inputOffset = this.input.offset();
      this.dropdown.css({
        width: (this.input.outerWidth() - dropdownBorderWidth) + "px",
        top: (inputOffset.top + this.input.outerHeight()) + "px",
        left: inputOffset.left + "px",
        Height:"150px",
        overflow:'auto'
      })
      var list = this.dropdownList.html("");
      $.each(this.results, function() {
        // list.append($("<li/>").html(this.name + " <small>[" + Math.round(this.score*100)/100 + "]</small>"));
        list.append($("<li/>").html(this.name));
      });
      this.dropdown.show();
      var frameHeight = (this.input.outerHeight()*(this.results.length));
      frameHeight = frameHeight<150?'150':frameHeight;
      this.myevent.css({
        position: 'absolute',
        width: (this.input.outerWidth() - dropdownBorderWidth-1) + "px",
        top:"0px",
        left: "0px",
        height:frameHeight+'px'
      })     
    },

    markSelected: function(n) {
      if (n > this.results.length) return;

      var rows = this.dropdown.find("li");
      rows.removeClass(this.settings.selectedClass);
      this.selectedIndex = n;

      if (n >= 0) $(rows[n]).addClass(this.settings.selectedClass);
    },

    pickSelected: function() {
    
      var selected = this.results[this.selectedIndex];
      var oldValue=this.hidden.val();
      if (selected) {
        this.input.val(selected.name);
        this.hidden.val(selected.value);
        this.picked = true;
        if(selected.value!=oldValue)
        this.input.trigger("onchange1") ;
      } else if (this.settings.allowMismatch) {
        this.hidden.val("");
      } else {
        this.reset();
      }
    },
                addOption: function(a,b) {
                        var obj = new Object();
                        obj.name=a;
                        obj.value=b;
                        obj.score="0.0";
                  this.cache.push(obj);
                  //µÚÒ»¸öÔªËØ×Ô¶¯Ñ¡ÖÐ
                          if(this.cache.length==1) {
                                this.setValue(b);
                          }
                        },
                removeOption: function() {
                        this.input.val("");
      this.hidden.val("");
                        this.cache = [];
                        },
    hide: function() {
      this.dropdown.hide();
      this.lastAbbreviation = null;
    },
        setValue: function(value){
                                var hide = this.hidden;
                                var thisin = this.input;
                                $.each(this.cache, function() {
                        if(this.value==value){
                                        hide.val(value);
                                        thisin.val(this.name);
                                }
                        });
                },
        getValue: function(){
                        return this.hidden.val();
                },
        getText: function(){
                        return this.input.val();
                },
        disabled: function() {
                this.input.attr("disabled",true);
        },
    moveSelected: function(n) { this.markSelected(this.selectedIndex+n); },
    markFirst:    function()  { this.markSelected(0); },
    markLast:     function()  { this.markSelected(this.results.length - 1); },
    reset:        function()  { this.input.val(this.abbreviationBeforeFocus); },
    focus:        function()  { this.input.focus(); },
    focusAndHide: function()  { this.focus; this.hide(); }
  });

  $.fn.flexselect = function(options) {
    this.each(function() {
      if (this.tagName == "SELECT"){
      var temp =         new $.flexselect(this, options);
      var obj = new Object();
      obj.id=this.id;
      obj.selectObject = temp;
        selectArray.push(obj);
        }
    });
    return this;
  };
})(jQuery);
分享到:
评论

相关推荐

    ios-TableView cell多选.zip

    nameStr=[selectArray componentsJoinedByString:@","]; NSLog(@"%@",nameStr); }else{ dmModel.checkboxOns=YES; [selectArray addObject:dmModel.name]; nameStr=[selectArray ...

    extjs grid

    var index = SelectArray.indexOf(rec.get('sum_jid')); if (index !== -1) { SelectArray.splice(index, 1); // 移除已取消选择的记录ID } } } }); // 给Store添加监听器 store.on({ load: function (store...

    PLSQL编程(存储器).docx

    示例中,`pro_emp_select`和`pro_emp_selectArray`展示了如何定义和使用IN参数,`pro_emp_selectArray`则进一步展示了IN/OUT参数的使用。 4. **异常处理**: PLSQL提供异常处理机制,如示例中的`exception when ...

    sqlserver转PG经验总结及PG的一些特性

    SELECT array_to_string(ARRAY['dfa', 'dfas', 'fds'], '?'); -- 使用 lpad 添加前导零 SELECT lpad('9', 6, '0'); ``` #### 四、PostgreSQL 特性介绍 除了以上提到的差异外,PostgreSQL 还拥有一些高级特性: 1...

    Java实现选择排序算法的实例教程

    SelectArray sArr = new SelectArray(); sArr.insert(89); sArr.insert(54); sArr.insert(667); sArr.insert(7); sArr.insert(12); sArr.insert(43); sArr.insert(12); sArr.display(); // 输出原始顺序 ...

    dbarray - 将数据库数组打包和解包为 matlab 数组:dbarray 允许您直接将数组 [] 类型的数据库字段发送/获取到本机 MATLAB 变量中-matlab开发

    % 为给定的数据库打包&gt; fastinsert(conn,'myTable',{'arrayField'},{Din}) % 高效插入&gt; Dout = fetch(conn,'select arrayField from myTable') % 高效获取&gt; outArray = dbarray.unpack(Dout{1}) % 将其解压回 ...

    postgresql-patterns-library:КоллекцияготовыхSQLзапросовдляPostgreSQLпочастовозникающимзадачам(получениеиоодификаци)

    КоллекцияготовыхSQLзапросовдля...SELECT ARRAY_TO_STRING(ARRAY_AGG(DISTINCT s ORDER BY s), ' , ' ) AS field_alias FROM ( VALUES ( ' b ' ), ( ' a ' ), ( ' b ' )) AS t(s);

    service_select_array.c

    : 网络编程-linux -select-数组优化

    详细讲解PostgreSQL中的全文搜索的用法

    CREATE INDEX idx_post_fulltext ON post USING gin(to_tsvector('english', coalesce(title, '') || ' ' || coalesce(content, '') || ' ' || coalesce((SELECT array_to_string(array_agg(name), ' ') FROM author...

    SHIFT

    SELECT array_agg(elem) INTO new_arr FROM unnest(arr) WITH ORDINALITY WHERE ordinality &gt; 1; ``` 4. 如果需要,可以将`temp_value`做进一步处理,比如插入到其他表或执行其他操作。 5. 更新原数组变量为新的...

    jquery/css需要记录的小知识(持续补充)

    self.selectArray[j].val(value).trigger('change'); ``` 这使得其他监听change事件的代码可以正常响应这个选择变化。 2. **jQuery正则匹配去掉字符串中的+号**: 在JavaScript中,使用正则表达式可以方便地替换...

    Dojo的Array处理

    Dojo 是一个强大的JavaScript工具库,它为开发者提供了丰富的功能,包括对Array对象的处理。在Dojo中,数组操作是一大亮点,因为它们提供了一系列高效且易用的方法,使得处理数组变得更加便捷。 首先,`dojo....

    Select模型

    ### Select模型概述 Select模型是网络编程中一种用于多路复用的技术,它允许一个进程同时监听多个套接字的状态变化。相比于传统的阻塞IO模型,Select模型通过非阻塞性质来提高程序效率和响应速度。下面我们将详细...

    vue+html select2

    type: Array, required: true, }, value: { type: [String, Number], default: null, }, }, data() { return { selectedValue: this.value, }; }, mounted() { this.$nextTick(() =&gt; { this.$refs....

    SelectBox 选择对话框

    % SELECTBOX is a dialog box for the user to select several % items from a list of available items. % % INPUT: % title = the title of the box % universe = a cellstring of available choices % selections...

    JS 将select options 排序

    const options = Array.from(selectElement.options); options.sort((a, b) =&gt; a.text.localeCompare(b.text)); while (selectElement.firstChild) { selectElement.removeChild(selectElement.firstChild); }...

    JavaScript模拟select

    ### JavaScript模拟select控件知识点详解 #### 一、引言 在前端开发中,有时我们需要对浏览器原生的`&lt;select&gt;`元素进行定制化处理,比如实现更丰富的样式或者增加额外的功能。本篇将深入探讨如何使用纯JavaScript...

    select2_ie8.rar

    IE8并不支持某些现代JavaScript特性,如Array.forEach、Array.map等,这可能导致Select2的一些功能无法正常工作。为了解决这个问题,我们需要引入一个polyfill库,如es5-shim和es5-sham,它们可以为老版本的...

    Select精美下拉框(漂亮)

    SS_VAR.SelectList = new Array(); SS_VAR.bEventAttached = false; var SS_CreatedElements = new Object(); function unloadObjects() { try { if (SS_VAR && SS_VAR.SelectList) { for (key in SS_VAR....

Global site tag (gtag.js) - Google Analytics