주어진 표 셀에 textarea
개의 요소 수를 얻고 싶습니다. 이를 사용하여 둘 이상의 요소가있는 경우에만 한 번에 하나의 요소에 제거 기능을 추가하고 '실행 취소'링크를 클릭하면 제거 된 textarea
을 실행 취소 할 수 있습니다.요소 수 확인 jQuery
<table class="result_table">
<tr valign="middle" align="center">
<td style="font-size:13px; " class="tbody_data side">Dissolution</td>
<td valign="middle" align="center" style="padding: 0px;" class="tbody_data">
<input type="hidden" value="2" name="tests[]">
<textarea style="border:none; vertical-align: middle;" class="det_st form-control">UV</textarea>
</td>
<td style="padding: 0px;" class="tbody_data">
<textarea style="border:none;" class="det_st form-control">USP 38 NF 33 Page 4635</textarea>
</td>
<td style="padding: 0px;" class="tbody_data">
<textarea style="border:none;" class="det_st form-control">Acid Stage Not more than 10.0% [n=6]
</textarea>
<textarea style="border:none;" class="det_st form-control">Buffer Stage Not Less than 70.0% [n=6]
</textarea>
</td>
<td style="padding: 0px;" class="tbody_data">
<textarea style="border:none;" class="det_st form-control"> Acid Stage 107.8% (RSD=5.2%; n=6) </textarea>
<textarea style="border:none;" class="det_st form-control"> Buffer Stage 102.2% (RSD=0.9%; n=6)</textarea>
</td>
<td style="padding: 25px; width:50px;" class="tbody_data side">
<select style="border:none; margin:15px; width:145px;" class="select" selected="selected">
<option value="COMPLIES">COMPLIES</option>
<option value="COMPLIES">COMPLIES</option>
<option value="DOES NOT COMPLY">DOES NOT COMPLY</option>
</select>
<select style="border:none; margin:15px; width:145px;" class="select" selected="selected">
<option value="COMPLIES">COMPLIES</option>
<option value="COMPLIES">COMPLIES</option>
<option value="DOES NOT COMPLY">DOES NOT COMPLY</option>
</select>
</td>
</tr>
</table>
$(document).on('mouseover', '.result_table tr td', function() {
$('textarea', this).dblclick(function() {
$(this).remove()
alert($(this).length) //gives one even when a cell contains two teatareas
});
})
제안 환영합니다 : 다음 샘플 코드 조각입니다.
'.length'는 여기에 친구입니다. – melancia
또한 유용 할 수 있습니다 : [.detach()] (https://api.jquery.com/detach/) – melancia
'.length'는 메소드가 아닙니다. [.length] (https://api.jquery.com/length/) – melancia