从下拉列表中禁用所选的选项 [英] Disable selected option from dropdown

查看:82
本文介绍了从下拉列表中禁用所选的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI
我的aspx页面中有六个具有相同值的下拉列表.如果用户从第一个下拉列表中选择了第一个项目,则该选择的项目将从其他下拉列表中禁用.
用户只能选择一次任何选项.

这是我的代码:-
这段代码在IE7以外的Mozila中都可以正常工作.我希望它在IE7中也可以正常工作.
---脚本----->

HI
I have six dropdownlist with same values in my aspx page.If user selected first item from first dropdowlist then that selected item sholud be disabled from other dropdownlist.
user should select any option only once.

here is my code:-
This code is working properly in Mozila except IE7.I want it should work in IE7 also.
--- script----->

<script type="text/javascript">

        $(function () {
            
            $('select').each(function (cSelect) {
                $(this).data('stored-value', $(this).val());
            });
            
            $('.ddlselect').change(function () {
                var previousVal = $(this).data('stored-value'); //get previous selected value
                var selectedVal = $(this).val(); //get selected dropdown value 

                $(this).data('stored-value', selectedVal); //set new selected value

                var eleid = $(this).attr("id");
                $(".ddlselect").each(function () {

                    if ($(this).attr("id") !== eleid) {
                        $(this).parent().find('option[value="' + selectedVal + '"]:not(:selected)').attr('disabled', 'disabled');
                    }
                });
            });
        });
        
    </script>



-控件---->



-- controls---->

<asp:DropDownList ID="DropDownList_1" runat="server" CssClass="ddlselect">
       <asp:ListItem>1
       <asp:ListItem>2
       <asp:ListItem>3
       <asp:ListItem>4
       <asp:ListItem>5
       <asp:ListItem>6
       <asp:ListItem>7
       <asp:ListItem>8
       <asp:ListItem>9
       <asp:ListItem>10


   <asp:DropDownList ID="DropDownList_2" runat="server" CssClass="ddlselect">
       <asp:ListItem>1
       <asp:ListItem>2
       <asp:ListItem>3
       <asp:ListItem>4
       <asp:ListItem>5
       <asp:ListItem>6
       <asp:ListItem>7
       <asp:ListItem>8
       <asp:ListItem>9
       <asp:ListItem>10

   <asp:DropDownList ID="DropDownList_3" runat="server" CssClass="ddlselect">
       <asp:ListItem>1
       <asp:ListItem>2
       <asp:ListItem>3
       <asp:ListItem>4
       <asp:ListItem>5
       <asp:ListItem>6
       <asp:ListItem>7
       <asp:ListItem>8
       <asp:ListItem>9
       <asp:ListItem>10




任何想法如何禁用IE7中的dropdownlist选项.
或者我们需要为此使用特定版本的jQuery.

谢谢
Ashish




Any idea how disable the option of dropdownlist in IE7.
Or we need to use specific version of jQuery for this.

Thanks
Ashish

推荐答案

( function (){


(' 选择').each(函数( cSelect){
('select').each(function (cSelect) {


().data(' 存储值'


这篇关于从下拉列表中禁用所选的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆