"document.getElementByClass가 함수가 아닙니다."
함수를 실행하려고 합니다.onclick
에 관해서는 어느 것이 없는class="stopMusic"
발생합니다. Firebug에서 오류가 발생합니다.
document.getElementByClass가 함수가 아닙니다.
여기 내 코드가 있습니다.
var stopMusicExt = document.getElementByClass("stopButton");
stopButton.onclick = function() {
var ta = document.getElementByClass("stopButton");
document['player'].stopMusicExt(ta.value);
ta.value = "";
};
당신 말은 아마도 당신이document.getElementsByClassName()
(그리고 결과 노드 목록에서 첫 번째 항목을 가져옵니다.)
var stopMusicExt = document.getElementsByClassName("stopButton")[0];
stopButton.onclick = function() {
var ta = document.getElementsByClassName("stopButton")[0];
document['player'].stopMusicExt(ta.value);
ta.value = "";
};
여전히 오류가 발생할 수 있습니다.
document.getElementsByClassName
함수가 아닙니다.
그러나 이전 브라우저에서는 이전 브라우저를 지원해야 할 경우 폴백 구현을 제공할 수 있습니다.
추가 오류 점검에 참여하기 전에 먼저 오류 여부를 확인하십시오.
document.getElementsByClassName() 자체.
getElements를 두 번 확인하고 notElement를 확인합니다.
다른 사람들이 말했듯이, 당신은 올바른 기능 이름을 사용하고 있지 않으며 모든 브라우저에 보편적으로 존재하지 않습니다.
ID가 있는 요소가 아닌 다른 요소의 크로스 브라우저 가져오기를 수행해야 하는 경우document.getElementById()
, 그럼 모든 브라우저에서 CSS3 셀렉터를 지원하는 라이브러리를 구하실 것을 강력히 권해드립니다.이를 통해 개발 시간, 테스트 및 버그 수정에 소요되는 막대한 시간을 절약할 수 있습니다.jQuery를 사용하는 것이 가장 쉬운 방법입니다. jQuery는 매우 광범위하게 사용할 수 있고, 문서화가 우수하며, 무료 CDN 액세스가 가능하며, 질문에 답변할 수 있는 훌륭한 커뮤니티가 있기 때문입니다.필요 이상으로 느껴진다면, 그냥 셀렉터 라이브러리인 Sizzle을 얻을 수 있습니다(실제로는 jQuery 등의 셀렉터 엔진입니다).다른 프로젝트에서 혼자 사용해 본 적이 있는데 쉽고 생산적이며 작습니다.
여러 노드를 한 번에 선택하려면 여러 가지 방법을 사용할 수 있습니다.모든 클래스를 동일하게 제공할 경우 다음과 같이 수행할 수 있습니다.
var list = document.getElementsByClassName("myButton");
for (var i = 0; i < list.length; i++) {
// list[i] is a node with the desired class name
}
그리고 해당 클래스 이름을 가진 노드 목록을 반환합니다.
시즐에서, 이것은 다음과 같습니다.
var list = Sizzle(".myButton");
for (var i = 0; i < list.length; i++) {
// list[i] is a node with the desired class name
}
jQuery에서는 다음과 같습니다.
$(".myButton").each(function(index, element) {
// element is a node with the desired class name
});
Sizzle과 jQuery 모두에서 다음과 같이 여러 클래스 이름을 셀렉터에 입력할 수 있으며 훨씬 더 복잡하고 강력한 셀렉터를 사용할 수 있습니다.
$(".myButton, .myInput, .homepage.gallery, #submitButton").each(function(index, element) {
// element is a node that matches the selector
});
그럴 것 같네요.getElementsByClassName
, ㅇgetElementByClass
. 보기 - https://developer.mozilla.org/en/DOM/document.getElementsByClassName .
일부 브라우저/버전에서는 이 기능을 지원하지 않을 수 있습니다.
제 솔루션은 다음과 같습니다.
변경 사항:
document.getElementsByClassName('.className')
받는 사람:
document.querySelector('.className')
철자를 잘못 썼으니 "GetElementsByClassName"이어야 합니다.
var objs = document.getElementsByClassName("stopButton");
var stopMusicExt = objs[0]; //retrieve the first node in the stack
//your remaining function goes down here..
document['player'].stopMusicExt(ta.value);
ta.value = "";
document.getElementsByClassName - CLASS 특성이 여러 개체에 할당하는 데 사용되므로 둘 이상의 항목을 가진 노드 스택을 반환합니다.
그럴 것 같네요.getElementsByClassName
것은 아니다.getElementByClassName
==> 놓쳤네요"s"
인에Elements
const collectionItems = document.getElementsByClassName('.item');
document.getElementByClass
함수가 아닙니다.
예, 기능이나 방법이 아닙니다. 그래야 하기 때문입니다.document.getElementsByClassName
document.querySelectorAll
잘 작동하고 선택 범위를 더욱 좁힐 수 있습니다.
https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
그getElementByClass
존재하지 않습니다. 아마도 사용하려고 할 것입니다.getElementsByClassName
. 그러나 대체 접근법을 사용할 수 있습니다(각도/값/반응에 사용...).템플릿)
function stop(ta) {
console.log(ta.value) // document['player'].stopMusicExt(ta.value);
ta.value='';
}
<input type="button" onclick="stop(this)" class="stopMusic" value='Stop 1'>
<input type="button" onclick="stop(this)" class="stopMusic" value='Stop 2'>
enter code here
var stopMusicExt = document.getElementByClass("stopButton").value;
stopButton.onclick = function() {
var ta = document.getElementByClass("stopButton");
document['player'].stopMusicExt(ta.value);
ta.value = "";
};
// .value will hold all data from class stopButton
만약 당신이 이 "getElementByClassName"을 썼다면, 당신은 "document.getElementByClass is not function"이라는 오류를 만나게 될 것이고, 그 오류를 극복하기 위해서는 "getElementsByClassName"이라고 쓰기만 하면 됩니다.Element가 아닌 Elements여야 하기 때문입니다.
언급URL : https://stackoverflow.com/questions/7480496/document-getelementbyclass-is-not-a-function
'programing' 카테고리의 다른 글
삽입 쿼리를 완료하는 데 이렇게 오랜 시간이 걸리는 이유는 무엇입니까? (0) | 2023.10.31 |
---|---|
.htaccess password protected 폴더가 404페이지로 이동합니다. (0) | 2023.10.31 |
Linear Layout으로 화면 하단에 버튼을 넣으시겠습니까? (0) | 2023.10.31 |
MariaDB 데이터베이스 표시 권한 (0) | 2023.10.31 |
Symfony와 WordPress가 함께 실행되는 nginx 구성 (0) | 2023.10.31 |