Javascript에서 Div 및 해당 요소 활성화 및 비활성화
이 질문에 이미 답변이 있습니다.
- 모든 div 콘텐츠를 비활성화하는 방법 26 답변
내가 할 수있는 방법을 찾고 활성화 및 비활성화 사업부 아이디 = "dcalc" 과 그 아이들.
<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 의 attr()
또는 prop()
함수를 통해 설정할 수 있습니다.
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);
다시 활성화하려면 "disabled"를 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()
요소를 다시 비활성화하는 요구 사항을 지정하지 않았으므로 클릭 처리기를 첨부했습니다. 따라서 아마도 이벤트는 한 번만 처리하면됩니다. 물론 당신은을 변경할 수 있습니다 .one()
에 .click()
적절한 경우.
참고URL : https://stackoverflow.com/questions/8423812/enable-disable-a-div-and-its-elements-in-javascript
'IT Share you' 카테고리의 다른 글
Ruby에서 시간을 가장 가까운 15 분으로 내림하는 방법은 무엇입니까? (0) | 2020.11.25 |
---|---|
PHP에서 함수를 덮어 쓸 수 있습니까? (0) | 2020.11.25 |
HorizontalScrollView의 스크롤바 숨기기 (0) | 2020.11.25 |
매개 변수 앞의 const vs 함수 이름 뒤의 const c ++ (0) | 2020.11.25 |
Android 날짜 선택기에서 지난 날짜를 비활성화하는 방법은 무엇입니까? (0) | 2020.11.25 |