Javascript Jquery';不同的事件有相同的功能
我的代码是这样的Javascript Jquery';不同的事件有相同的功能,javascript,jquery,Javascript,Jquery,我的代码是这样的 $(document).ready(function(){ nodeClick(elm = ''); }); function nodeClick() { if(elm != ''){ var obj = ''; }else{ obj = $('.hitarea') } obj.live('click',function(){ $(this).ad
$(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函数,即不使用out click。如何在不使用out click的情况下触发该函数函数nodeclick in不接受任何参数并传递它。在其中添加参数,然后像这样在调用中传递它
$(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
}
我对这句话感到非常困惑,但要触发
单击事件,请使用.trigger()
:
等等,什么?你能解释一下吗?我想在elm变量为空时自动触发click函数这会在elm变量为空时自动触发click函数吗??我不认为这会导致obj的点击,obj.click();我在编辑之前读了这个问题。这就是你触发点击事件的方式。它(触发)会与活动元素一起工作吗?我的意思是,这些元素是用ajax动态创建的
obj.trigger('click');