2014-11-09 2 views
0

아직 jquery를 배우므로 무지를 용서하십시오.jquery에서 검사 된 모든 행에 대해 "선택"옵션을 설정 하시겠습니까?

여러 행이 포함 된 테이블이 있습니다. 각 행은 <select> 태그를 가지고 있으며 함수를 실행할 때 그 값을 "토글 (toggle)"하고 싶습니다. 그래서 여기에 테이블 예를 들어 어떻게 표시되는지를 보여줍니다 :

<table align="center" class="table table-bordered table-hover table-condensed table-responsive"> 
    <thead> 
    ... 
    </thead> 
    <tbody> 
    <tr> 
     <td class="text-center"><input id="item_ids_" name="item_ids[]" type="checkbox" value="11521"></td> 
     <td class="text-center">Item value here</td> 
     <td class="text-center"> 
     <select class="form-control" id="item_11521_color" name="item[11521][color]"> 
      <option selected="selected" value="None">None</option> 
      <option value="Blue">Blue</option> 
      <option value="Orange">Orange</option> 
      <option value="Green">Green</option> 
      <option value="Yellow">Yellow</option> 
      <option value="Purple">Purple</option> 
     </select> 
     </td> 
     <td class="text-center"> 
     <select class="form-control" id="item_11521_test" name="item[11521][test]"> 
      <option selected="selected" value="None">None</option> 
      <option value="First">First</option> 
      <option value="Second">Second</option> 
     </select> 
     </td> 
    </tr> 
    </tbody> 
</table> 

어떻게 <option value="Blue"><option value="Orange">에 각 행을 반복하고 값 (텍스트)을 변경할 수 있습니다 등 내가이 기능을 실행할 때마다?

+0

이 기능을 수행하는 데 필요한 세부 정보를 추가하십시오. –

+0

단순히 선택한 모든 행에 대해 "옵션"의 첫 번째 그룹을 변경하십시오. – LewlSauce

답변

2

이게 당신이 찾고 있는게 있나요? 단순성을 위해 선택에

<button id="change">change all to Green and first</button> 

및 클래스 :

<select class="form-control color-select" id="item_11521_color" name="item[11521 [color]"> 
<select class="form-control position-select" id="item_11521_test" name="item[11521][test]"> 

EDIT :

제작

$("#change").on("click", function() { 

    // loop throw all rows 
    $("table tr").each(function() { 

     // on a row, find the checkbox and change the values if it's checked 
     if($(this).find("input[type='checkbox']").prop("checked")) { 
      $(this).find(".color-select").val("Green"); 
      $(this).find(".position-select").val("First"); 
     } 

    }); 

}); 

변경을 수행하는 버튼이 추가 (코드 업데이트) 코드를 변경해야합니다.

업데이트 된 콘텐츠 : http://jsfiddle.net/theagitator/44vqugf0/1/

+0

일종. 그러나 jsfiddle 데모의 체크 박스는 행이 수정되는 것을 결정하지 않습니다. 이것은 내가하고 싶은 일입니다. 매우 가깝다. 감사합니다. – LewlSauce

+0

옵션이 아직 변경되지 않은 경우 행의 체크 박스를 선택해야합니까? 나는 여기서 당신이 가고있는 것을 이해하기 위해 고심하고있다. – balzafin

+0

여러 행을 포함하는 테이블이 있습니다. 확인란을 선택하면 각 행의 "대량 변경" "파란색"옵션을 "주황색"으로 변경합니다. – LewlSauce

관련 문제