내 상사의 요구에 맞게 javascript accordian 메뉴를 수정하려고합니다. 그러나 이제 대부분의 조정 작업을 완료 했으므로 가상 벽돌 벽을 맞았습니다. expandInit() 함수는 전달중인 인수를 수락하지 않습니다. "Object expected"오류가 계속 발생하지만 typeof()를 사용하여 함수의 인수를 테스트하고 인수가 Object임을 반환합니다. 그래서 나는 곤두박질 쳤습니다. 누군가이 빛을 발할 수있는 빛은 매우 도움이 될 것입니다. 나는 collapseInit() 코드를 포함하지 않았지만javascript 함수가 전달 된 개체 변수를 받아들이지 않음
function $(id){
return document.getElementById(id);
}
function expandTimer(div){
if(getHeight(div) < div.maxh){
var velocity = Math.round((div.maxh - getHeight(div))/div.speed);
velocity = (velocity < 1) ? 1 : v;
velocity = (getHeight(div) + velocity);
setHeight(div, velocity+'px');
div.style.opacity = (velocity/div.maxh);
div.style.filter = 'alpha(opacity = '+(velocity * 100/div.maxh)+');';
} else {
setHeight(div, div.maxh);
clearInterval(div.refRate);
}
}
//arg types are String, Int, and, String.
function accordian(mother, speed, alternate){
var motherObj = $(mother);
motherObj.activeNode='';
var allDivs = motherObj.getElementsByTagName('div');
for (var i = 0; i < allDivs.length; i++){
var divID = allDivs[i].id;
if (divID.substr(divID.indexOf('-') + 1, divID.length) == 'header'){
var contentID = divID.substr(0, divID.indexOf('-'))+'-content';
var divObj = $(divID);
divObj.contentNode = contentID;
divObj.hightlight = alternate;
var contentObj = $(contentID);
contentObj.style.display = 'none';
contentObj.style.overflow = 'hidden';
contentObj.maxh = getHeight(contentObj);
contentObj.speed = speed;
contentObj.refRate;
divObj.onmouseover = function(){
if (this.parentNode.activeNode != ''){
collapseInit($(this.parentNode.activeNode));
}
alert (typeof($(this.contentNode))); //returns 'object'
//code executes fine up until here.
expandInit($(this.contentNode));
this.parentNode.activeNode = this.contentNode;
}
}
}
}
,이 같은 문제가있다 :
다음은 관련 코드입니다. 위에 언급 된 다른 모든 함수가 의도 한대로 작동한다고 가정하자.
편집 : 죄송합니다. 올바른 기능을 포함하지 않았습니다.
function expandInit(div){
alert("in expandInit"); //<---does not execute.
setDisplay(div,'block');
div.style.height='0px';
clearInterval(div.refRate);
div.refRate = setInterval('expandTimer('+div+')', 10);
}
'expandInit' 무엇입니까 ... 내가 거기 expandInit 기능이 표시되지 않습니다,하지만 난이 expandTimer 기능을 참조하십시오 여기에 expandInit() 함수는입니까? 정의를 링크하거나 붙여 넣을 수 있습니까? –
브라우저 캐시를 지우셨습니까? (이전 Js 코드가 유지되었을 수 있습니다)? – VirtualTroll
'this.contentNode'가'undefined'이거나 jQuery 객체이기 때문에'null' 인 경우에도'typeof ($ (this.contentNode))'는 항상'object'입니다. 아마도'this.parentNode.activeNode'가 실제로 무엇인지보아야 할 것입니다 (디버거를보세요). 추가 도움이 필요하면'expandInit()'에 대한 코드를 포함하십시오. – jfriend00