HTML 및 자바스크립트 Tip > html

본문 바로가기

html

HTML 및 자바스크립트 Tip

작성일 07-05-28 17:12

페이지 정보

작성자서방님 조회 82회 댓글 0건

본문

* autocomplete="off" 로 브라우저의 자동 완성 기능을 사용하지 못하게 할 수 있다.

예:  <form id="form" autocomplete="off" method="post" ...

* 자바 스크립트 비교 연산자 (이런 심오한 뜻이....)
a == b : a와 b의 값이 같은지 비교
a === b : a,b의 값은 물론 타입도 같은지 비교
더 자세히: http://research.nihonsoft.org/javascript/CoreReferenceJS15/ops.html#1003191

* DOM 오퍼레이션 document.getElementById(arg);
HTML 태그 id 속성으로 DOM 객체 반환
더 자세히: http://www.w3schools.com/htmldom/met_doc_getelementbyid.asp

* label 태그의 for 속성
다른 input 태그의 id를 가리킨다.
즉, 해당 input 값을 위한 라벨(범례)을 위한 것이다.
예:
<form name="input" action="">
<input type="radio" name="sex" id="male" />
<label for="male">Male</label>
<br />
<input type="radio" name="sex" id="female" />
<label for="female">Female</label>
</form>
더 자세히: http://www.w3schools.com/tags/tag_label.asp

 

document.all 을 쓰지 맙시다!

출처 : OKJSP에서 스크랩

document.all 을 안쓰는 것 많으로도 표준을 따르는 웹 페이지 디자인에 매우 큰 걸음을 내 딛는 것입니다.
단지 저 document.all 때문에 다른 안되는 홈페이지가 부지기수 입니다.
요즘에는 FireFox가 어쩔수 없이 지원해서 되긴합니다만, 그렇다고 그게 좋다는 것을 의미하지는 않습니다. FireFox 1.0 은 document.all 을 지원하긴 하지만 if 문으로 체크하면 지원하지 않는다고 표시합니다.
다음은 한국 모질라 포럼에 올라온 글입니다.
http://forums.mozilla.or.kr/viewtopic.php?t=580&highlight=document.all
-----------------
웹사이트에서 버튼이 동작 되지 않는 경우 대부분 Javascript의 객체를 MSDOM에서 사용하는 document.all을 사용하기 때문에 그렇습니다.
자바스크립트 디버거를 통해 소스를 보았을 때 document.all 이 들어 있는 경우
document.all 대신 W3C DOM의 오브젝트 판별법을 사용하도록 웹사이트 관리자에게 알려주셔야 합니다.
document.all[objectID] -> document.getElementById("objectID")
혹시 거기에서 MS IE4 때문에 getElementById를 쓸 수 없다고 하면 getObject()를 아래처럼 정의한 후에 쓸 수 있다고 알려 주십시오.
function getObject(objectId) {
// checkW3C DOM, then MSIE 4, then NN 4.
//
if(document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId);
}
else if (document.all && document.all(objectId)) {
return document.all(objectId);
}
else if (document.layers && document.layers[objectId]) {
return document.layers[objectId];
} else {
return false;
}
}
즉, 다음처럼 하면 됩니다.
getObject('sendbn').style.visibility="hidden";
getObject는 http://www.orient-express.com/js/layers.inc 에 있습니다.
혹은 다음에 있는 'x library'를 쓰는 것도 좋은 방법입니다. http://www.cross-browser.com

 

http://www.orient-express.com/js/layers.inc 의 내용
function getStyleObject(objectId) {
// checkW3C DOM, then MSIE 4, then NN 4.
//
if(document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId).style;
  }
  else if (document.all && document.all(objectId)) {
return document.all(objectId).style;
  }
  else if (document.layers && document.layers[objectId]) {
return document.layers[objectId];
  } else {
return false;
  }
}
function getObject(objectId) {
// checkW3C DOM, then MSIE 4, then NN 4.
//
if(document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId);
  }
  else if (document.all && document.all(objectId)) {
return document.all(objectId);
  }
  else if (document.layers && document.layers[objectId]) {
return document.layers[objectId];
  } else {
return false;
  }
}
function changeObjectVisibility(objectId, newVisibility) {
   // first get a reference to the cross-browser style object
   // and make sure the object exists
   var styleObject = getStyleObject(objectId);
   if(styleObject) {
styleObject.visibility = newVisibility;
return true;
   } else {
// we couldn't find the object, so we can't change its visibility
 return false;
   }
}
function displayText(objectId, text){
if (document.all) {
document.all[objectId].innerHTML = text;
}
else
{
var obj = document.getElementById(objectId);
obj.innerHTML = text;
}
}

댓글목록

등록된 댓글이 없습니다.

게시물 검색
Copyright © 서방님.kr All rights reserved.
PC 버전으로 보기