jquery onclick run
I need to run all onclick events on page load. how can I do something like this:
$('.upload').foreach(function(){
//execute onclick for found element (ex: test(this, 'var') )
});
<div class="upload开发者_如何学Python" onclick="test(this, 'var')">text</div>
I hate to give you a 'this will take some work' answer, but it is considered bad practice to use onclick events these days. Since you are already using jQuery, I would recommend using one of jQuery's event binding utilities to replace your onclicks.
.click()
, .delegate()
, .live()
and .bind()
will all be helpful in this.
However...
Also since you're using jQuery, you just need to fire .click()
on them if you're really not interested in bringing your code up to current standards. ;-)
You can use the click() or trigger() methods to do that.
$('.upload').each(function(){
$(this).click();
});
A demo of it work.
This should do the job:
$('.upload').each(function(){
$(this).click();
});
But there is probably a better solution to whatever you are trying to achieve.
精彩评论