나는 인자 요소의 자식 노드를 보여 주거나 숨기는 (유산) JS 함수를 가지고있다. img
태그를 숨기려면 mouseover
및 mouseout
이벤트 처리기에 사용됩니다. 기능은 다음과 같습니다DOCTYPE break style.display
function displayElem(elem, value, handlerRoot){
try{
var display = 'inline';
if(!value)
display = 'none';
if(handlerRoot)
elem.style.display = display;
var childs = elem.childNodes;
for (i = 0; i < childs.length; i++){
if(childs[i].nodeType == Node.ELEMENT_NODE){
childs[i].style.display = display;
alert("Node "+childs[i].tagName+" style set to " +childs[i].style.display);
}
}
}catch(e){
alert('displayElem: ' + e);
}
}
여기
, value
및 handlerRoot
부울 플래그입니다. 대상 HTML 페이지에 doctype이없는 경우이 함수는 완벽하게 작동합니다. 어떤 doctype (strict 또는 transitional)을 추가하면이 문제가 해결됩니다. 경고 표시 스타일은 올바른 값으로 설정되었지만 하위 요소는 표시되지 않습니다.
이 기능이 DOCTYPE과 함께 작동하면 좋을 것입니다.
이미지 (elem
의 자식 노드) (? 아마 뭔가 여기 잘못)과 같이 초기화 :
var img = new Image();
img.style.cssText =
'background: transparent url("chrome://{appname}/content/dbutton.png") right top no-repeat;' +
'position: relative;' +
'height:18px;'+
'width:18px;'+
'display:none;';
어떤 브라우저에서 문제가 발생합니까? –
AFAIK 'cssText' 속성은 IE 전용입니다. – RoToRa
나는 cssText를 1x1 스타일 속성 설정으로 대체했습니다. 동일한 결과입니다. 이처럼 : img.style.background = '투명 URL ("chrome : // {appname} /content/dbutton.png") 오른쪽 상단의 반복 없음'; img.style.position = '상대적'; img.style.height = '18px'; img.style.width = '18px'; img.style.display = '없음'; – manuna