드롭 다운에서 선택한 항목에 따라 특정 필드를 숨기거나 표시하려고합니다. 다음 코드가 있습니다.
$("#button").click(function() {
alert("handler called");
$("#name").hide();
$(document).ready(function(){
$("#selection").on('change', function() {
alert("handler called1");
if ($("#selection").val() == "day")
{
$("#name").show();
}
});
});
});
내 HTML은
<div class="selection" id = "selection">
<tbody><td><label>selection</label></td>
<td><select class="selection"></select></td>
</tbody>
</div>
<div class="name" id = "name">
<tbody><td><label>Name</label></td><td><input type="text" </input></td>
</tbody>
</div>
그만큼
alert("handler called")
잘 작동합니다. 그리고
$("#name").hide();
또한 작동합니다. 그러나 실제 선택 기반 숨기기 / 표시가 작동하지 않는 두 번째 부분입니다. 드롭 다운 메뉴에서 선택한 항목을 캡처 할 수없는 것 같습니다. 조언 부탁드립니다.
현재 버튼 클릭 핸들러에서 문서 준비 핸들러를 바인딩하고 있으며 문서가 이미로드되었으므로 select
.
사용하다
$(document).ready(function() {
$("#button").click(function() {
alert("handler called");
$("#name").hide();
});
$(".selection").on('change', function() {
alert("handler called1");
if ($(this).val() == "day") {
$("#name").show();
}
});
});
또한 사용하고 있기 때문에 Class Selector(".class")
를 사용해야합니다.<select class="selection"></select>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다