SlideDown然后调用自定义函数

发布于 2024-08-26 01:17:42 字数 421 浏览 12 评论 0原文

很难理解为什么我的函数被调用两次。

我试图检测何时调用单选按钮(intRev_yes),检查div是否为空,向下滑动另一个div,然后调用动态创建日期字段的custome函数。

if(this.id=="intRev_yes"){
 if($('div#mainField').is(':empty')){
  $('.intRevSections').slideDown('slow',function(){
   current=-1;
   addIrField();
  });
 }   
}

当我在每个阶段发出警报时,在到达末尾(即 addIrField())后,脚本似乎返回到 SlideDown() 部分并调用 addIrField()。我不明白为什么,没有循环。 current 用作日期字段的索引。

Having difficulty understanding why my function is being called twice.

I'm trying to detect when a radio button is called (intRev_yes), check if a div is empty, slide down another div and then call a custome function which dynamically creates a date field.

if(this.id=="intRev_yes"){
 if($('div#mainField').is(':empty')){
  $('.intRevSections').slideDown('slow',function(){
   current=-1;
   addIrField();
  });
 }   
}

When I alert out at each stage, after getting to the end (i.e. addIrField()), the script seems to go back to the slideDown() section and recalls addIrField(). I can't understand why, there are no loops. current is used as an index for the date field.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

演出会有结束 2024-09-02 01:17:42

您可能是从冒泡的 Dom 事件中调用此函数的。请参阅 http://en.wikipedia.org/wiki/DOM_events 检查情况是否如此。

You are probably calling this from a Dom event that bubbles. See http://en.wikipedia.org/wiki/DOM_events to check if that's the case.

故事未完 2024-09-02 01:17:42

另一种情况是:

如果您有两个类名为 .intRevSections 的元素,slideDown 将运行两次,回调将触发两次...

希望这会有所帮助,Sinan。

Another case would be:

If you have two elements having class name .intRevSections slideDown would run twice, and callback would fire twice...

Hope this helps, Sinan.

七度光 2024-09-02 01:17:42

司南已经发现了这个问题,但实际上并没有发布答案。答案是:

找出为什么你有两个 div(如果你从 JS 创建它们,另一个函数也可能运行两次)

你可能还想修复代码,以便它只使用一个 div,即使你有两个 div

 $('.intRevSections:first').slideDown('slow',function(){
   current=-1;
   addIrField();
  });

Sinan already discovered the problem, but did not in fact post an answer. the answer is:

Find out why You have two divs (if You create them from JS the other function might be run twice as well)

You may also want to fix the code so that it uses only one div even if You have two of them

 $('.intRevSections:first').slideDown('slow',function(){
   current=-1;
   addIrField();
  });
梦罢 2024-09-02 01:17:42

试试这个:

if (this.id == "intRev_yes") {
        if ($('div#mainField').is(':empty')) {
            $('.intRevSections').slideDown('slow', function(event) {
                event.stopPropagation();
                current = -1;
                addIrField();
            });
        }
    }

try this:

if (this.id == "intRev_yes") {
        if ($('div#mainField').is(':empty')) {
            $('.intRevSections').slideDown('slow', function(event) {
                event.stopPropagation();
                current = -1;
                addIrField();
            });
        }
    }
┾廆蒐ゝ 2024-09-02 01:17:42

Jquery animate 完整为我工作

 $('.intRevSections:first').slideDown('slow',function(){
    complete: addIrField();
 });

Jquery animate complete worked for me

 $('.intRevSections:first').slideDown('slow',function(){
    complete: addIrField();
 });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文