日期:2014-05-16  浏览次数:20330 次

关于JS函数的写法,求解!!!!!!
如下,请问大家是什么意思,看不懂
<script type="text/javascript">
ddaccordion.init({
  headerclass: "submenuheader", //Shared CSS class name of headers group
  contentclass: "submenu", //Shared CSS class name of contents group
  revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click","clickgo", or "mouseover"
  mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
  collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
  defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
  onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
  animatedefault: false, //Should contents open by default be animated into view?
  persiststate: true, //persist state of opened contents within browser session?
  toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
  togglehtml: ["suffix", "<img src='images/plus.png' class='statusicon' />", "<img src='images/minus.png' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
  animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
  oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
  //do nothing
  },
  onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
  //do nothing
  }
})
</script>

------解决方案--------------------
ddaccordion.init这个函数被执行了

该函数只有一个参数 Object类型
{}配置对象写法,生成的是一个Object类型变量

例如:
var obj={name:'name',value:'1',eat:function(){}};
等价于:
var obj=new Object();
obj.name='name';obj.value='1';obj.eat=function(){};

{}里面配置了一个对象作为ddaccordion.init的参数,明白了么?
------解决方案--------------------
这个是ddaccordion这个对象的初始化
该方法肯定是在设计一个javascript插件,而这个函数就是为了初始化这个插件要使用的一些变量
好处主要是:可以统一化设置参数,代码看起来清爽!如果在插件各处都使用var定义一些变量的话,你会觉得代码没有逻辑性!
------解决方案--------------------
探讨

ddaccordion.init这个函数被执行了

该函数只有一个参数 Object类型
{}配置对象写法,生成的是一个Object类型变量

例如:
var obj={name:'name',value:'1',eat:function(){}};
等价于:
var obj=new Object();
obj.name='name';obj.value='1';obj.eat……

------解决方案--------------------
HTML code
var initOjb = {
  headerclass: "submenuheader", //Shared CSS class name of headers group
  contentclass: "submenu", //Shared CSS class name of contents group
  revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid    value: "click","clickgo", or "mouseover"
  mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
  collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
  defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
  onemustopen: fal