我有一个DOM元素数组。如果单击第四个,我想隐藏搜索框。如果单击其他任何一个,我想显示它。我该怎么做?我目前有:

var app = {
    config: {
        tabs: [$("#tab1"), $("#tab2"), $("#tab3"), $("#tab4")],
        search: $("#search")
    },
    showHideSearch: function () {
        // Here I need to test if the fourth tab was clicked on then hide();
        // else if tabs one through three were clicked show
    }
}
app.showHideSearch();


任何帮助表示赞赏。谢谢。

最佳答案

$.each(app.config.tabs, function(i, v) {
  v.bind('click', function(){
    $('#searchbox').show();
    if(i==3)
      $('#searchbox').hide();
  });
});

关于javascript - 如果单击数组中的元素,如何触发click事件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8607463/

10-12 06:55