버튼을 클릭하면 선택 기반 값을 얻으려고합니다. 여기 내 코드입니다.
<tr>
<td width="50%"><a href="clients_detail.asp?clientID=470">ABC Corp</a></td>
<td width="50%">
<select id="salesPersonID" name="salesPersonID" class="form-control">
<option value="" 0""="">Select Contact</option>
<option value="424">Aaron Fick</option>
<option value="492">John Smith</option>
</select>
</td>
<td style="text-align:center;"><button type="submit" class="btn btn-info but_save" data-clientid="470" data-column="salesPersonID" data-carrierid="0">save</button>
</td>
</tr>
<tr>
<td width="50%"><a href="clients_detail.asp?clientID=471">CDEF Corp</a></td>
<td width="50%">
<select id="salesPersonID" name="salesPersonID" class="form-control">
<option value="" 0""="">Select Contact</option>
<option value="424">Aaron Fick</option>
<option value="492">John Smith</option>
</select>
</td>
<td style="text-align:center;"><button type="submit" class="btn btn-info but_save" data-clientid="470" data-column="salesPersonID" data-carrierid="0">save</button>
</td>
</tr>
두 번째 행의 버튼을 클릭하면 바로 위에있는 선택 상자의 값을 가져오고 싶습니다. 여기에 내가 사용중인 코드가 있지만 제대로 이해하지 못하는 것 같습니다.
$(document).on('click','.but_save',function(){
var value = $(this).closest('td.select').val();
});
당신은 사용해야합니다 $(this).parent().prev('td').find('select').val()
$(this)
가져옵니다 <button>
.parent()
버튼의 <td>
.prev('td')
이전 요소를 가져옵니다. <td>
.find('select')
내부 선택을 가져옵니다 <td>
$(document).on('click','.but_save',function(){
var value = $(this).parent().prev('td').find('select').css('border','1px solid red').val();
console.log(value);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td width="50%"><a href="clients_detail.asp?clientID=470">ABC Corp</a></td>
<td width="50%">
<select id="salesPersonID" name="salesPersonID" class="form-control">
<option value="" 0""="">Select Contact</option>
<option value="424">Aaron Fick</option>
<option value="492">John Smith</option>
</select>
</td>
<td style="text-align:center;"><button type="submit" class="btn btn-info but_save" data-clientid="470" data-column="salesPersonID" data-carrierid="0">save</button>
</td>
</tr>
<tr>
<td width="50%"><a href="clients_detail.asp?clientID=471">CDEF Corp</a></td>
<td width="50%">
<select id="salesPersonID" name="salesPersonID" class="form-control">
<option value="" 0""="">Select Contact</option>
<option value="424">Aaron Fick</option>
<option value="492">John Smith</option>
</select>
</td>
<td style="text-align:center;"><button type="submit" class="btn btn-info but_save" data-clientid="470" data-column="salesPersonID" data-carrierid="0">save</button>
</td>
</tr>
</table>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다