Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript函数不接受传递的对象变量_Javascript_Function_Argument Passing - Fatal编程技术网

javascript函数不接受传递的对象变量

javascript函数不接受传递的对象变量,javascript,function,argument-passing,Javascript,Function,Argument Passing,我正试图修改javascript手风琴式菜单,以满足我老板的需要。然而,现在我已经做了大部分的调整,我遇到了一个虚拟的障碍。函数expandInit不接受我传递给它的参数。我一直得到对象预期的错误,但我已经使用typeof测试了函数的参数,它返回的参数是一个对象。所以我被难住了,任何人能提供的任何信息都会非常有用 以下是相关代码: function $(id){ return document.getElementById(id); } function expandTimer(div){

我正试图修改javascript手风琴式菜单,以满足我老板的需要。然而,现在我已经做了大部分的调整,我遇到了一个虚拟的障碍。函数expandInit不接受我传递给它的参数。我一直得到对象预期的错误,但我已经使用typeof测试了函数的参数,它返回的参数是一个对象。所以我被难住了,任何人能提供的任何信息都会非常有用

以下是相关代码:

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;
      }
    }
  }
}
虽然我没有包含collapseInit代码,但它也有同样的问题。只需说,上面提到的所有其他功能都按预期工作

编辑:抱歉,没有包含正确的功能。以下是expandInit函数:

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函数,但我确实看到expandTimer函数

什么是expandInit?是否可以链接或粘贴定义?是否清除了浏览器缓存?它可能保留了旧的Js代码?类型$this.contentNode将始终为object,即使this.contentNode未定义或为null,因为它是jQuery对象。您可能需要在调试器中查看this.parentNode.activeNode实际上是什么。如果您需要进一步的帮助,请包括expandInit的代码。@jfriend00 OP没有使用jQuery,在本例中,美元函数被声明为getElementByIdfunction expandInitdiv的速记{alertin expandInit;setDisplaydiv,'block';div.style.height='0px';clearIntervaldiv.refRate;div.refRate=setInterval'expandTimer'+div+,10;}