자바스크립트에서 디브와 그 요소를 활성화 및 비활성화
div="dcalc" 및 해당 children을 활성화 및 비활성화하는 방법을 찾고 있습니다.
<div id="dcalc" class="nerkheArz"
style="left: 50px; top: 150px; width: 380px; height: 370px;
background: #CDF; text-align: center" >
<div class="nerkh-Arz"></div>
<div id="calc"> </div>
</div>
페이지를 로드할 때 비활성화한 다음 클릭으로 활성화할 수 있습니까?
이것이 제가 시도한 것입니다.
document.getElementById("dcalc").disabled = true;
다음과 같이 jQuery의 or 기능을 통해 설정할 수 있습니다.
jQuery(< 1.7):
// This will disable just the div
$("#dcacl").attr('disabled','disabled');
아니면
// This will disable everything contained in the div
$("#dcacl").children().attr("disabled","disabled");
jQuery(> = 1.7):
// This will disable just the div
$("#dcacl").prop('disabled',true);
아니면
// This will disable everything contained in the div
$("#dcacl").children().prop('disabled',true);
아니면
// disable ALL descendants of the DIV
$("#dcacl *").prop('disabled',true);
자바스크립트:
// This will disable just the div
document.getElementById("dcalc").disabled = true;
아니면
// This will disable all the children of the div
var nodes = document.getElementById("dcalc").getElementsByTagName('*');
for(var i = 0; i < nodes.length; i++){
nodes[i].disabled = true;
}
div의 모든 컨트롤을 비활성화하려면 div에 투명 div를 추가하여 비활성화하고 클릭할 수 없게 만들고 fadeTo를 사용하여 비활성화 모양을 만들 수 있습니다.
이거 먹어봐요.
$('#DisableDiv').fadeTo('slow',.6);
$('#DisableDiv').append('<div style="position: absolute;top:0;left:0;width: 100%;height:100%;z-index:2;opacity:0.4;filter: alpha(opacity = 50)"></div>');
다음은 모든 하위 요소를 선택하고 비활성화합니다.
$("#dcacl").find("*").prop("disabled", true);
그러나 입력, 버튼 등 특정 요소 유형을 비활성화하는 것이 정말 의미가 있으므로 보다 구체적인 선택기를 원합니다.
$("#dcac1").find(":input").prop("disabled",true);
// noting that ":input" gives you the equivalent of
$("#dcac1").find("input,select,textarea,button").prop("disabled",true);
다시 활성화하려면 "비활성화"를 false로 설정하면 됩니다.
페이지를 로드할 때 비활성화한 다음 클릭으로 활성화할 수 있습니다.
위 코드를 문서 준비 처리기에 넣고 적절한 클릭 처리기를 설정합니다.
$(document).ready(function() {
var $dcac1kids = $("#dcac1").find(":input");
$dcac1kids.prop("disabled",true);
// not sure what you want to click on to re-enable
$("selector for whatever you want to click").one("click",function() {
$dcac1kids.prop("disabled",false);
}
}
페이지 로드와 클릭 사이의 div에 더 많은 요소를 추가하지 않을 경우를 가정하여 셀렉터의 결과를 캐시했습니다.그리고 당신이 요소를 다시 비활성화하는 요구 사항을 지정하지 않았기 때문에 클릭 핸들러를 첨부했습니다. 아마도 이벤트는 한 번만 처리하면 될 것입니다.물론 변경할 수 있습니다..one()
로..click()
적당한 경우에는
언급URL : https://stackoverflow.com/questions/8423812/enable-disable-a-div-and-its-elements-in-javascript
'programing' 카테고리의 다른 글
Twitter Bootstrap 3에서 col-lg-push와 col-lg-pull을 이용한 열 순서 조작 (0) | 2023.10.19 |
---|---|
개발자 계정 회원 자격이 만료되면 내 앱은 어떻게 됩니까? (0) | 2023.10.19 |
리눅스에서 ssize_t는 어디에서 정의됩니까? (0) | 2023.10.19 |
자바 langNoClassDefFFoundError: javax/servlet/ServletContext (0) | 2023.10.19 |
PHP SoapClient에서 인증서 확인 사용 안 함 (0) | 2023.10.19 |