【问题标题】:What would be a good way to select one class or another class? [duplicate]选择一个班级或另一个班级的好方法是什么? [复制]
【发布时间】:2018-09-07 16:23:25
【问题描述】:

我正在尝试选择一个动态创建的类,或者另一个在 html 中创建的类。这样做的好方法是什么?

我试过这个:

$('.wrapper' || '.surround').on('click', '.bet-button', function(){}

还有这个:

$('.wrapper', '.surround').on('click', '.bet-button', function(){}

有没有办法写这个,到目前为止它似乎没有工作。

【问题讨论】:

  • 您还应该在末尾添加缺少的)

标签: javascript jquery


【解决方案1】:

你快到了:

只用逗号隔开

$('.wrapper, .surround').on('click', '.bet-button', function(){}

【讨论】:

  • 你能解释一下这有什么意义吗,我为什么要把逗号放在引号里面?不过感谢您的帮助!
  • @Bkes 因为这就是选择器的工作方式。这与 CSS 中的相同。如果将逗号放在字符串中,则将其传递给 jQuery。否则,您将调用 $(a, b),其计算结果为 $(b)(Javascript 逗号运算符)
  • 好的,谢谢!在那里玩了一会儿哈哈
  • @Bkes Chris 已经解释过:)
【解决方案2】:

你可以试试

$('.wrapper, .surround').on('click', '.bet-button', function(){}

【讨论】:

    猜你喜欢
    • 2017-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多