IE 7在Jquery中选择Dropdown disabled属性问题?

时间:2011-08-21 21:48:16

标签: javascript jquery select javascript-events

从过去三天开始,我正在尝试修复这些但无法解决问题。 这是我的询问,如果有人可以帮助我..

我的页面上有一些下拉列表,其中包含一些与安全相关的问题,如果用户已经从第一个选择了问题1,那么在所有剩余的下拉列表中应该禁用第一个问题。那么同样的情况应该适用于剩余的下拉列表。< / p>

我已经创建了我的脚本,但因为IE7中的每个人都禁用了属性,所以我创建了自定义脚本以禁用选择列表值,但这不能在第一次点击时工作..

HTML

<select name="select1" class="securityQuestions">
    <option value="0">Please select an option...</option>

    <option value="1">What is your favorite color?</option>
    <option value="2">What is your pet's name?</option>
    <option value="3">How old are you?</option>
</select>
<select name="select2" class="securityQuestions">
    <option value="0">Please select an option...</option>
    <option value="1">What is your favorite color?</option>

    <option value="2">What is your pet's name?</option>
    <option value="3">How old are you?</option>
</select>
<select name="select3" class="securityQuestions">
    <option value="0">Please select an option...</option>
    <option value="1">What is your favorite color?</option>
    <option value="2">What is your pet's name?</option>

    <option value="3">How old are you?</option>
</select>

这是我的剧本

通用脚本

(function($){
    $.fn.removeQuestions = function() {

        var wholeList = $(this);

        wholeList.focus(function() {
            // no of question lists on the page
              var listLength = wholeList.length;

            // array to hold which questions have been selected
            var questionArray = new Array(listLength);

            // loop to find index of questions selected, store in array
            $('option:selected').each(function(index, value) {
                questionArray[index] = $(this).index();
            });

            // loop over all question lists
            wholeList.each(function(index, value) {
                // remove any existing attr from previous selection
                $('option', this).removeAttr('disabled');

                // for each list hide each question in array
                for(j = 0; j <= questionArray.length; j++) {
                    // don't hide if it's  default 'choose your question'
                    if(!questionArray[j] == 0) {
                        $('option', this).eq(questionArray[j]).attr('disabled','disabled');
                    }
                }

                // now re-show the question selected in this list item.
                $('option', this).eq(questionArray[index]).removeAttr('disabled');

            });
        });
        return wholeList;
    }; // end of plugin
})(jQuery);



(function($) {

    $('select').change(function() {
        if(this.options[this.selectedIndex].disabled) {
            // Needs revision!
            if (this.options.length == 0) {
                this.selectedIndex = -1;
            } else {
                this.selectedIndex--;
            }
            $(this).trigger("change");
        }
    });
    $('select').mousedown(function(){       
        $(this).children('option[disabled]').each(function() {
            $(this).css({'color': '#cccccc'});
        });   
    });

})(jQuery);

0 个答案:

没有答案