Skip navigation.

exploreopera

| Help

Sign up | Help

极湖

无不用其“极”

Posts tagged with "Plugin"

jQuery plugin 改造:Select Box replacement

, ,

Select Box replacement 是一个用图片和text输入框代替select的Plugin,发现之后想用这个Plugin,试用过程中发现有不少问题,所以修改了一下代码。

由于改动比较多,就不一一细说了。

修改后的代码可以从这儿下载

jQuery 扩展小试: 取得列表选中项属性

, ,

想要以 jQuery 的方式取得列表中被选中项的文字,找来找去找不到现成的方法,只好现做一个:
(function($){
    /**
     * Get selected option's property
     */
    $.fn.getSelectedProperty = function(property) {
        var arrValue = Array();
        var a=0;
        this.each( function() {
            for (var i=0; i < this.options.length; i++) {
                if (this.options[i].selected == true) {
                    arrValue[a] = this.options[i][property]; 
                    a++;
                }
            }
        });
    
        if(arrValue.length > 1) {
            return arrValue;
        } else if(arrValue.length == 1) {
            return arrValue[0];
        }
        return '';
    };
})(jQuery);

以上函数,单选返回字符串,多选返回数组。

用法例:
alert($("#select_box_id").getSelectedProperty('text')); 
July 2008
SMTWTFS
June 2008August 2008
12345
6789101112
13141516171819
20212223242526
2728293031