如何将鼠标悬停事件更改为鼠标单击下面的编码事件

时间:2013-02-12 09:49:41

标签: javascript html css javascript-events

这是菜单的JavaScript代码,此脚本采用鼠标悬停事件的形式。但我需要将其更改为鼠标单击事件。请帮我改变这个。

    var dolphintabs={subcontainers:[], last_accessed_tab:null,

    revealsubmenu:function(curtabref){
    this.hideallsubs()
    if (this.last_accessed_tab!=null)
        this.last_accessed_tab.className=""
    if (curtabref.getAttribute("rel")) //If there's a sub menu defined for this tab     item, show it
    document.getElementById(curtabref.getAttribute("rel")).style.display="block"
    curtabref.className="current"
    this.last_accessed_tab=curtabref
    },

      hideallsubs:function(){
          for (var i=0; i<this.subcontainers.length; i++)
            document.getElementById(this.subcontainers[i]).style.display="none"
},


     init:function(menuId, selectedIndex){
    var tabItems=document.getElementById(menuId).getElementsByTagName("a")
        for (var i=0; i<tabItems.length; i++){
            if (tabItems[i].getAttribute("rel"))
                       this.subcontainers[this.subcontainers.length]=tabItems[i].getAttribute("rel") //store id of submenu div of tab menu item
        if (i==selectedIndex){ //if this tab item should be selected by default
            tabItems[i].className="current"
            this.revealsubmenu(tabItems[i])
        }
    tabItems[i].onmouseover=function(){
    dolphintabs.revealsubmenu(this)
    }
    } //END FOR LOOP
}

 }

样品请参见以下链接。 Click Here to View the Sample of it http://www.javascriptkit.com/script/script2/tabset/index.shtml

1 个答案:

答案 0 :(得分:1)

更改此

tabItems[i].onmouseover=function(){
    dolphintabs.revealsubmenu(this)
}

tabItems[i].onclick=function(){
    dolphintabs.revealsubmenu(this)
}