jquery로 콤보박스의 선택된 값을 불러오는 경우가 많은데 대부분의 경우 id보다는 find를 사용해 roof를 돌려 this를 사용하는 경우가 많다(그리드에서)

이때 option에 selected를 안해주면 값을 못읽는 경우가 있고 이를 위해서 값을 매핑 시킬 때 꼭 attr("selected", "selected"); 설정을 해줘야 하며 attr("selected", "selected"); 설정도 find를 이용해서 roof를 돌려주는 하기의 방법 밖에는 없다...ㅠ

 

$actionTrSelect = $("#gvList > tbody > tr:last").find("td Select");

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

                    if (id == "ddlTargetYear"){
                        $(this).val(YearAlias);

                        $(this).find("option").each(function() {
                            if($(this).val() == YearAlias) {
                                $(this).attr("selected", "selected");
                            }
                        });
                    }
                    if (id == "ddlSalesUserId"){
                        $(this).val(SalesUserId);

                        $(this).find("option").each(function() {
                            if($(this).val() == SalesUserId) {
                                $(this).attr("selected", "selected");
                            }
                        });
                    }
                    if (id == "ddlCUST01"){
                        $(this).val(CUST01);

                        $(this).find("option").each(function() {
                            if($(this).val() == CUST01) {
                                $(this).attr("selected", "selected");
                            }
                        });
                    }
                    if (id == "ddlCUST04"){
                        $(this).val(CUST04);

                        $(this).find("option").each(function() {
                            if($(this).val() == CUST04) {
                                $(this).attr("selected", "selected");
                            }
                        });
                    }


                    $(this).hide();
                });

 

나같은 삽질을 피하기 위해 공유 합니다.

'IT > jquery' 카테고리의 다른 글

table merge  (0) 2017.02.26
jquery find each 거꾸로  (0) 2017.01.03
table 안의 체크된 체크박스 Row 값 알아내기  (0) 2016.12.15
table 안의 라디오버튼 하나씩 체크  (0) 2016.12.15
file 등록 후 img 미리보기  (0) 2016.12.14

+ Recent posts

 

 

jquery로 콤보박스의 선택된 값을 불러오는 경우가 많은데 대부분의 경우 id보다는 find를 사용해 roof를 돌려 this를 사용하는 경우가 많다(그리드에서)

이때 option에 selected를 안해주면 값을 못읽는 경우가 있고 이를 위해서 값을 매핑 시킬 때 꼭 attr("selected", "selected"); 설정을 해줘야 하며 attr("selected", "selected"); 설정도 find를 이용해서 roof를 돌려주는 하기의 방법 밖에는 없다...ㅠ

 

$actionTrSelect = $("#gvList > tbody > tr:last").find("td Select");

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

                    if (id == "ddlTargetYear"){
                        $(this).val(YearAlias);

                        $(this).find("option").each(function() {
                            if($(this).val() == YearAlias) {
                                $(this).attr("selected", "selected");
                            }
                        });
                    }
                    if (id == "ddlSalesUserId"){
                        $(this).val(SalesUserId);

                        $(this).find("option").each(function() {
                            if($(this).val() == SalesUserId) {
                                $(this).attr("selected", "selected");
                            }
                        });
                    }
                    if (id == "ddlCUST01"){
                        $(this).val(CUST01);

                        $(this).find("option").each(function() {
                            if($(this).val() == CUST01) {
                                $(this).attr("selected", "selected");
                            }
                        });
                    }
                    if (id == "ddlCUST04"){
                        $(this).val(CUST04);

                        $(this).find("option").each(function() {
                            if($(this).val() == CUST04) {
                                $(this).attr("selected", "selected");
                            }
                        });
                    }


                    $(this).hide();
                });

 

나같은 삽질을 피하기 위해 공유 합니다.

'IT > jquery' 카테고리의 다른 글

table merge  (0) 2017.02.26
jquery find each 거꾸로  (0) 2017.01.03
table 안의 체크된 체크박스 Row 값 알아내기  (0) 2016.12.15
table 안의 라디오버튼 하나씩 체크  (0) 2016.12.15
file 등록 후 img 미리보기  (0) 2016.12.14

+ Recent posts