简体   繁体   English

在甜蜜警报中运行 jquery

[英]Run jquery inside sweet alert

I have some rows where the user can click and then I run a jQuery function, everything working fine.我有一些用户可以点击的行,然后我运行一个 jQuery 函数,一切正常。

As some rows have extra options I decided to load those extra options in a popup window using sweet alert and they should do the same (when the row inside the sweet alert is clicked run same function)由于某些行有额外的选项,我决定使用甜蜜警报在弹出窗口中加载这些额外选项,它们应该做同样的事情(当点击甜蜜警报内的行时,运行相同的功能)

The problem is that the rows inside the sweet alert popup are not calling any function on click.问题是甜蜜警报弹出窗口中的行没有在点击时调用任何函数。 Why can be this?为什么会是这个?

Can I use sweet alert for this or should I look for other plugin?我可以为此使用甜蜜警报还是应该寻找其他插件?

This is how I'm calling the jQuery function这就是我调用 jQuery 函数的方式

$('.maincontent').on('click', '.betHandle', function () {
    add(this);
});

I think there is one of two possible reasons it isn't working.我认为它不起作用的两个可能原因之一。

  1. as @sweaver2112 has suggested, your .betHandle may not be under .maincontent in the DOM tree正如@sweaver2112 所建议的,您的.betHandle可能不在 DOM 树中的.maincontent
  2. you're adding the listener before .maincontent is added to the DOM.maincontent添加到 DOM 之前添加监听器

In either case, adding the listener to the body will work:在任何一种情况下,将侦听器添加到正文都将起作用:

$('body').on('click', '.betHandle', function () {
   add(this);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM