모두 비활성화하는 방법jQuery와 함께 폼 안에?
<form id="target">
....
</form>
이전 버전에서는 을 사용할 수 있습니다.jQuery 1.6 기준으로 다음을 대신 사용해야 합니다.
$("#target :input").prop("disabled", true);
'target' 내부의 모든 폼 요소를 비활성화합니다.참조:
모든 입력, 텍스트 영역, 선택 및 버튼 요소와 일치합니다.
당신이 원하는 것이.<input>
요소:
$("#target input").prop("disabled", true);
위의 예는 기술적으로 올바르지 않습니다.최신 jQuery에서는prop()
방법은 장애인과 같은 것들에 사용되어야 합니다.해당 API 페이지를 참조하십시오.
'target' 내부의 모든 양식 요소를 비활성화하려면 모든 입력, 텍스트 영역, 선택 및 버튼 요소와 일치하는 :input 선택기를 사용합니다.
$("#target :input").prop("disabled", true);
요소만 원하는 경우 이것을 사용합니다.
$("#target input").prop("disabled", true);
또한 보다 간결한 방법은 실렉터 엔진을 사용하는 것입니다.따라서 Div 또는 Form 부모의 모든 Form 요소를 비활성화합니다.
$myForm.find(':input:not(:disabled)').prop('disabled',true)
추가할 수 있습니다.
<fieldset class="fieldset">
그리고 나서 당신은 전화할 수 있습니다.
$('.fieldset').prop('disabled', true);
이 한 줄로 양식의 입력 필드를 비활성화할 수 있습니다.
$('form *').prop('disabled', true);
쓰기만큼 쉬운 모든 양식을 비활성화하려면:
jQuery 1.6+
$("#form :input").prop("disabled", true);
jQuery 1.5 이하
$("#form :input").attr('disabled','disabled');
다음과 같이 할 수 있습니다.
//HTML BUTTON
<button type="button" onclick="disableAll()">Disable</button>
//Jquery function
function disableAll() {
//DISABLE ALL FIELDS THAT ARE NOT DISABLED
$('form').find(':input:not(:disabled)').prop('disabled', true);
//ENABLE ALL FIELDS THAT DISABLED
//$('form').find(':input(:disabled)').prop('disabled', false);
}
Gnarf는 최종 답변(버전 1.6에서 jQuery api에 대한 변경 사항 포함)을 제공했습니다.
언급URL : https://stackoverflow.com/questions/1416900/how-to-disable-all-input-inside-a-form-with-jquery
'programing' 카테고리의 다른 글
일부 SQLite3 테이블의 데이터를 덤프하려면 어떻게 해야 합니까? (0) | 2023.08.17 |
---|---|
문자열에 알파벳 문자가 포함되어 있는지 확인하려면 어떻게 해야 합니까? (0) | 2023.08.17 |
cURL에서 HTTP 헤더가 있는 API 키 전달 (0) | 2023.08.17 |
부트스트랩 입력 포커스 파란색 표시 변경 (0) | 2023.08.12 |
Angular 'ngOnInit'의 비동기/대기 (0) | 2023.08.12 |