테이블에는 드롭 다운 상자와 <td>
값이 있는 법선 이 포함됩니다 . 때 onChange
드롭 다운의 특정은 <td>
다른 드롭으로 변경해야합니다. 함수를 구현하기 위해 jQuery를 사용했지만 첫 번째 행의 드롭 다운을 변경하는 동안 전체 테이블에 대해 변경이 발생합니다. onChange
함수가 호출 된 단일 행에 대해 변경이 발생하기 만하면 됩니다.
$('td:nth-child(11),th:nth-child(11)').hide();
$('td:nth-child(10),th:nth-child(10)').show();
10 번째와 11 번째 열을 숨기고 표시하는 데 사용됩니다.
doc.ready function () :
$(document).ready(function() {
$('td:nth-child(11),th:nth-child(11)').show();
$('td:nth-child(10),th:nth-child(10)').hide();
// ...
onChange 함수 사용 :
$(document).on('change','.mySelect', function(event) {
event.preventDefault();
$('td:nth-child(11),th:nth-child(11)').hide();
$('td:nth-child(10),th:nth-child(10)').show();
//$(this).closest("td").show();
var _this = $(this);
var id =_this.val();
var statusValue = id;
$.get('AssignedTo', { statusVal : statusValue }, function(response) {
var select = _this.closest("tr").find("select[name='assigned']");
/* var select = $('#assigned'); */
select.find('option').remove();
$.each(response, function(index, value) {
$('<option>').val(value).text(value).appendTo(select);
});
});
});
를 사용하는 대신 사용 nth-child
을 고려 eq()
하십시오. 더 깨끗하고 .NET의 일부 특이성 문제가 없습니다 nth-child
.
<td>
"변경된"행의 모든 요소 를 가져 오려면 다음을 사용하여 모든 형제를 선택 <td>
하고 부모 를 가져올 수 있습니다..closest("td")
.siblings("td")
형제 자매 뿐만 아니라 원본을 포함하려면 .addBack()
.
마지막으로 행에 모든 셀이 있으므로을 사용하여 원하는 셀을 선택하십시오 eq()
.
모두 합치면 다음과 같습니다.
//Select the 11th cell in the row
var $cell = $(this).closest('td').siblings('td').addBack().eq(10);
또는, 부모를 얻고 사용 (대신 형제의) 모든 아이들이 선택할 수 .closest("tr")
및 children()
:
//Select the 11th cell in the row
var $cell = $(this).closest("tr").children("td").eq(10);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다