2012-06-11 32 views
-1

我的代碼是這樣的jQuery的不同事件的相同功能

$(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 


    }); 

} 

如果榆樹變量是空的,我需要調用我可以觸發函數了點擊與出click.how即自動點擊功能

+0

等等,什麼?你能解釋一下嗎? – Blender

+0

我想在elm變量爲空時自動觸發點擊函數 – coolguy

回答

0

我敢用的措辭混淆,但觸發事件click,使用.trigger()

obj.trigger('click'); 
+0

我的問題的編輯請有結果 – coolguy

+0

我在編輯之前閱讀問題。這就是觸發點擊事件的方式。 – Blender

+0

它會(觸發器)與實時元素一起工作..我的意思是元素是用ajax動態創建的 – coolguy

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 


} 
+0

當elm變量爲空時,這會自動觸發點擊函數嗎?我不這麼認爲 – coolguy

+0

這可能會導致點擊obj,obj.click(); – Adil

相關問題