开发者

How do I trigger a function?

开发者 https://www.devze.com 2023-04-07 07:33 出处:网络
I have this code: <a href=\"#\" class=\"button\" id=\"buyme\" ></a> <a href=\"#\" id=\"buy\" onclick=\"placeOrder(\'10\');return false;\"><开发者_开发技巧;span id=\"please\">cl

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消