admin管理员组文章数量:1390204
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);
});
});
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);
});
});
Share
Improve this question
edited Mar 31, 2011 at 15:39
rosscj2533
9,3237 gold badges41 silver badges57 bronze badges
asked Mar 28, 2011 at 18:04
nilsnils
3353 gold badges5 silver badges16 bronze badges
7
- show the full code and markup, when you assign the handler? – vittore Commented Mar 28, 2011 at 18:05
- Where did you put that piece of code? It should be in a "ready" handler. – Pointy Commented Mar 28, 2011 at 18:05
-
Where are the variables
realPlayer
andgameState
ing from? – gen_Eric Commented Mar 28, 2011 at 18:05 -
Is
raisebuttonaction
script being included before this bind script? – BrunoLM Commented Mar 28, 2011 at 18:06 -
Where/when is this code being run? Part of
$(document.ready)
? – AlG Commented Mar 28, 2011 at 18:06
1 Answer
Reset to default 3Assuming 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.
本文标签: javascriptButton onclick to click() jqueryStack Overflow
版权声明:本文标题:javascript - Button onclick to click() jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744632500a2616626.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论