반응형
jquery에서 드롭 다운 상자 활성화 / 비활성화
jQuery를 처음 사용하고 확인란을 사용하여 드롭 다운 목록을 활성화 및 비활성화하고 싶습니다. 이것은 내 HTML입니다.
<select id="dropdown" style="width:200px">
<option value="feedback" name="aft_qst">After Quest</option>
<option value="feedback" name="aft_exm">After Exam</option>
</select>
<input type="checkbox" id="chkdwn2" value="feedback" />
이 작업을 수행하려면 어떤 jQuery 코드가 필요합니까? 또한 좋은 jQuery 문서 / 연구 자료를 검색합니다.
이해하기 쉬운 한 가지 방법이 있습니다.
$(document).ready(function() {
$("#chkdwn2").click(function() {
if ($(this).is(":checked")) {
$("#dropdown").prop("disabled", true);
} else {
$("#dropdown").prop("disabled", false);
}
});
});
시도-
$('#chkdwn2').change(function(){
if($(this).is(':checked'))
$('#dropdown').removeAttr('disabled');
else
$('#dropdown').attr("disabled","disabled");
})
나는 JQuery> 1.8을 사용하고 있으며 이것은 나를 위해 작동합니다 ...
$('#dropDownId').attr('disabled', true);
$("#chkdwn2").change(function(){
$("#dropdown").slideToggle();
});
이 시도
<script type="text/javascript">
$(document).ready(function () {
$("#chkdwn2").click(function () {
if (this.checked)
$('#dropdown').attr('disabled', 'disabled');
else
$('#dropdown').removeAttr('disabled');
});
});
</script>
활성화 / 비활성화하려면-
$("#chkdwn2").change(function() {
if (this.checked) $("#dropdown").prop("disabled",true);
else $("#dropdown").prop("disabled",false);
})
데모-http: //jsfiddle.net/tTX6E/
if-else가없는 더 나은 솔루션 :
$(document).ready(function() {
$("#chkdwn2").click(function() {
$("#dropdown").prop("disabled", this.checked);
});
});
$("#chkdwn2").change(function() {
if (this.checked) $("#dropdown").prop("disabled",'disabled');
})
$(document).ready(function() {
$('#chkdwn2').click(function() {
if ($('#chkdwn2').prop('checked')) {
$('#dropdown').prop('disabled', true);
} else {
$('#dropdown').prop('disabled', false);
}
});
});
성명 .prop
에서 사용 if
.
참고 URL : https://stackoverflow.com/questions/7703241/enable-disable-a-dropdownbox-in-jquery
반응형
'IT TIP' 카테고리의 다른 글
BroadcastReceiver에서 서비스 시작 (0) | 2020.11.22 |
---|---|
대소 문자를 구분하지 않는 알파벳 순서의 SQLite 쿼리 (0) | 2020.11.22 |
CRAN Ubuntu 저장소에서 R 설치 : 공개 키 오류 없음 (0) | 2020.11.22 |
동일한 서버에있는 다른 데이터베이스의 백업에서 새 데이터베이스를 생성 하시겠습니까? (0) | 2020.11.22 |
자바 스크립트에서 연도가 윤년인지 확인하십시오. (0) | 2020.11.22 |