How do I trigger a function?
I have this code:
<a href="#" class="button" id="buyme" ></a>
<a href="#" id="buy" onclick="placeOrder('10');return false;"><开发者_开发技巧;span id="please">click me</span></a>
<script>
$('#buyme').click(function() {
$('#buy').trigger(function(placeOrder('10')));
});
</script>
<script>
function placeOrder(var) {
.....
}
</script>
What I want to do is when I click on #buyme
to trigger the onclick
from the #buy
link or to trigger the function from inside onClick
.
My example doesn't seem to do it. Any ideas?
edit:
for some reason :
$('#buyme').click(function() {
$("#buy").click();
});
doesn't work
Just call the function yourself:
$('#buyme').click(function() {
placeOrder('10');
});
You could also trigger the click event of the button and let it call the function (seems a bit backwards though):
$('#buyme').click(function() {
$("#buy").click();
});
$("#buyme").click(function(){
$("#buy").click();
});
Just use click()
. According to docs, calling it without an argument triggers the event.
$('#buy').click();
This bit: function(placeOrder('10'))
is invalid. Replace it with:
$('#buy').click();
精彩评论