admin管理员组文章数量:1391987
I have a function called "go()" which needs to be called thrice on page load. Right now I have called it on the ready event of a div with class "nav". Can someone suggest how can I call the go function thrice. Adding go() calls one after other calls it only once.
$('.nav').ready(function() {
go();
});
I have a function called "go()" which needs to be called thrice on page load. Right now I have called it on the ready event of a div with class "nav". Can someone suggest how can I call the go function thrice. Adding go() calls one after other calls it only once.
$('.nav').ready(function() {
go();
});
Share
Improve this question
edited Jun 3, 2009 at 13:48
Rene Saarsoo
13.9k10 gold badges62 silver badges91 bronze badges
asked Jun 3, 2009 at 13:39
theranemantheraneman
1,6304 gold badges20 silver badges32 bronze badges
5 Answers
Reset to default 4Even though you say this does not work, it should...
$('.nav').ready(function() {
go();
go();
go();
});
Update: If there is an error in your go() function, it might terminate execution before go() returns for the first time. Run in Firebug and see if you are getting any errors.
$('.nav').ready(function() {
go();
go();
go();
});
Should call it three times.
As other people have stated, placing the calls one-after-the-other should have called it three times. Perhaps there something that go() is doing that is not being done more than once due to how the function is called, etc. It might be helpful to take a closer look at go() - please post that code and/or explain why you need to call it 3 times.
Like rikh sayd, you must be mistaken.
Please test that you can see three hello-s when you replace your go() function with something like this:
function go() {
alert("hello");
}
I think I understand what you're trying to do...in the best terms as I can possibly describe since I've not taken a single jQuery class, just learned bits and pieces on my own through places like this website. I was doing something similar. I needed a datepicker
to call twice, for two different fields that needed a calendar to pop up - for a check-in and check-out date in a form
. In my head I did this, I made two separate scripts with two separate and different id
values:
<script>
$( function() {
$( "#datepicker" ).datepicker();
} );
</script>
<script>
$( function() {
$( "#datepicker2" ).datepicker();
});
</script>
And my form
in the body
of my webpage looks like this:
For my Check-In Date:
<input name="DateIn" type="text" id="datepicker" style="width:90px"/>
For my Check-Out Date:
<input name="DateOut" type="text" id="datepicker2" style="width:90px">
So I guess you need to make 3 scripts each with #go1
, #go2
, #go3
in your head and corresponding calls in your html
. I hope this helps.
本文标签: javascriptCalling a function more than once in jQueryStack Overflow
版权声明:本文标题:javascript - Calling a function more than once in jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744745168a2622831.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论