开发者

Button onclick to click() jquery

I have a button that reacts to onclick() at the moment, but I want it to work with jquery.

$('#nupp1').click(function() {
    raiseButtonAction(realPlayer, gameState);
});

raisebuttonaction is in another .js This piece of code isn't working. Am I doing something wrong? edit1:

$(document).ready(function() {
    $('#nupp1').click(function() {
        raiseButtonAction开发者_开发百科(realPlayer, gameState);
    });
});


Assuming you have this:

<head>
    <scripts />
</head>
<body>
    <a id="nupp1"></a>
</body>

You code will not work. jQuery will not be able to find the element. The element must exists for that function to work. So

<a id="nupp1"></a>
<script />

Will work because a is being rendered before the script.

You can also use $(document).ready or $() to execute your function when the DOM nodes load.

Or you can use jQuery.live.

jQuery API

  • ready Specify a function to execute when the DOM is fully loaded.
  • live Attach a handler to the event for all elements which match the current selector, now and in the future.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜