-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変数が空の場合、クリック関数を自動的に呼び出す必要があります。つまり、クリックなしで呼び出す必要があります。クリックなしでその関数をトリガーするにはどうすればよいですか。

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 に答える