다음은 간략한 소개입니다.
첫 번째는 js에서 객체를 얻는 방법으로, 페이지에 여러 ID가 있는 경우 이렇게 긴 document.getElementBy(를 작성해야 합니다. "id")
document.getElementBy("id")
document.getElementById의 약어
개인적으로 프로토타입에서 document.getElementById 정의를 사용하는 것이 좋습니다.
함수 $()
{
var elements = new Array();
for (var i = 0; i < 인수.길이; i )
{
var element = 인수[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
요소 반환;
}
다음 코드를 사용하여 정의할 수도 있습니다.
function $(objectId) {
if(document .getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId);// W3C DOM
} else if (document.all && document.all(objectId)) {
return document .all(objectId);// MSIE 4 DOM
} else if (document.layers && document.layers[objectId]) {
return document.layers[objectId];// NN 4 DOM. . 참고: 중첩된 레이어는 찾을 수 없습니다.
} else {
return false;
}
}
두 번째는 jquery에서 ID 가져오기
메서드는 이 기사
http://www.jb51.net/article/27617.htm http://www.jb51.net/article/26702.htm