我正在嘗試讓 if/else 陳述句在 jQuery 中作業。根據用戶在我們平臺上的選擇,.card-decorator-brand-curve 添加了 card-decorator-stroke 或 card-decorator-stroke-none。
card-decorator-stroke 可以按我想要的方式作業,但 card-decorator-stroke-none 不行。
JS如下:
$('.card-decorator-brand-curve').each(function() {
if ($(this).find('card-decorator-stroke')) {
$(this).removeClass('card-decorator-stroke');
$(this).addClass('brand-curve-stroke');
console.log("test me");
} else {
$(".card-decorator-stroke-none").removeClass('brand-curve-stroke');
console.log("test me 2");
}
});
任何幫助我完成此修復程式的幫助都非常感謝。
謝謝
uj5u.com熱心網友回復:
$(this).find('card-decorator-stroke') 回傳一個始終為真的 jQuery 物件。
if($(this).find('card-decorator-stroke').length)
uj5u.com熱心網友回復:
我的大腦可能整天都被編碼炸了,但我終于想通了。
$('.card-decorator-brand-curve').each(function() {
if ($('.card-decorator-brand-curve').hasClass('card-decorator-stroke')){
$('.card-decorator-brand-curve').addClass('brand-curve-stroke');
$('.card-decorator-brand-curve').removeClass('card-decorator-stroke');
console.log('test');
} else {
$('.card-decorator-stroke-none').removeClass('brand-curve-stroke');
console.log('test me');
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/363774.html
標籤:javascript html 查询 css
上一篇:根據單擊復選框過濾資料
下一篇:從字體真棒圖示播放聲音
