gpt4 book ai didi

jquery - 如何检查点击按钮的第二类?

转载 作者:行者123 更新时间:2023-12-01 03:04:08 25 4
gpt4 key购买 nike

如果我有两个按钮,一个带有 apple 类,另一个带有 appleorange 类:

<button class="apple"/>
<button class="apple orange"/>

apple 按钮的按钮单击事件中,如何判断单击的按钮是否也有 orange 类?

$("button.apple").click(function(event) 
{
var hasOrange = // ???
}

最佳答案

jQuery 提供 .hasClass()只是为了这个目的:

$("button.apple").click(function(event) 
{
var hasOrange = $(this).hasClass('orange');
}

关于jquery - 如何检查点击按钮的第二类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4492767/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com