Develope/jQuery

JQury selectbox option

친절한 웬디양~ㅎㅎ 2013. 5. 14. 15:37
반응형

jQuery(document).ready(function() {
        // 등록/수정 버튼 클릭 이벤트
        jQuery(":input:image[name*=ImgBtnInput]").click(function() {
            return checkForm();
        });
   
        // 목록 버튼 클릭 이벤트
        jQuery(":input:image[name*=ImgBtnList]").click(function() {
            return goList();
        });
      
      
        // 메인 팝업 선택시 이벤트
        jQuery($('select[name*=DdlPrintType]')).change(function() {
            var val = jQuery($('select[name*=DdlPrintType]')).val();
            if(val=="N"){
                // 기본값을 하나 제외하고 삭제
                $("select[name*=DdlNoticeType] option[value='1']").remove();
                $("select[name*=DdlNoticeType] option[value='2']").remove();
                // 새로운 항목 추가.
                jQuery($('select[name*=DdlNoticeType]')).append("<option value='1'>이벤트</option>"); 

//=> 그냥 비활성화만 원할시에... 위 3라인 삭제.. 아래 주석 풀기..

//                  $("select[name*=DdlNoticeType] option[value='1']").attr("disabled", true); 
//                  $("select[name*=DdlNoticeType] option[value='2']").attr("disabled", false);

 


            }
            else
            {
                // 기본값을 하나 제외하고 삭제
                $("select[name*=DdlNoticeType] option[value='1']").remove();
                $("select[name*=DdlNoticeType] option[value='2']").remove();
                // 새로운 항목 추가.
                jQuery($('select[name*=DdlNoticeType]')).append("<option value='2'>긴급공지</option>");   

//=> 그냥 비활성화만 원할시에... 위 3라인 삭제.. 아래 주석 풀기..

//                  $("select[name*=DdlNoticeType] option[value='1']").attr("disabled", false);
//                  $("select[name*=DdlNoticeType] option[value='2']").attr("disabled", true); 
            }
        });
    });

 

 

==================== 화면단 코드. aspx

<asp:DropDownList ID="DdlPrintType" runat="server" Width="150px" Font-Size="9pt" Font-Names="돋움">
                    <asp:ListItem Selected="True" Value="Y">Y</asp:ListItem>
                    <asp:ListItem Value="N">N</asp:ListItem>
                </asp:DropDownList>

▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ 

<asp:DropDownList ID="DdlNoticeType" runat="server" Width="150px" Font-Size="9pt" Font-Names="돋움">
                    <asp:ListItem Selected="True" Value="0">공지</asp:ListItem>
                    <asp:ListItem Value="1" >이벤트</asp:ListItem>
                    <asp:ListItem Value="2">긴급공지</asp:ListItem>
                </asp:DropDownList>

=====================

 

일단 selectbox 컨트롤에 애를 많이 먹은 관계로... 보관용...

근데 좋은 코드인지는 모르겠음...

반응형