-1

我的代码是这样的

    $(document).ready(function(){     
        nodeClick(elm = '');   
    });

function nodeClick()
{ 
    if(elm != ''){
        var obj = '';
    }else{
        obj = $('.hitarea')
    }

    obj.live('click',function(){   
    $(this).addClass('something');
    $(this).attr('something',1);
    //lots of this reference are here


    });

}

如果 elm 变量为空,我需要自动调用 click 函数,即不点击。如何在不点击的情况下触发该函数

4

2 回答 2

0

函数 nodeclick 不接受任何参数并且您传递它。在其中添加参数,然后像这样在调用中传递它。

 $(document).ready(function(){     
     elm = '';
        nodeClick();   
    });

function nodeClick(elm)
{ 
    if(elm != ''){
        var obj = '';
    }else{
        obj = $('.hitarea')
    }

    obj.live('click',function(){   
    $(this).addClass('something');
    $(this).attr('something',1);
    //lots of this reference are there are

        /****
          if elm variable is empty i  need to call these function automatically ie        with out click.how can i trigger that function with out click
       ******/
    });

   obj.click(); //You can call click event handler like this


}
于 2012-06-11T05:26:40.923 回答
0

我对措辞很困惑,但要触发click事件,请使用.trigger()

obj.trigger('click');
于 2012-06-11T05:30:11.033 回答