gpt4 book ai didi

javascript - 更改事件按钮图标的单选按钮应为 OutlineIcon 或 FillledIcon

转载 作者:行者123 更新时间:2023-11-29 21:30:29 25 4
gpt4 key购买 nike

这是我的 HTML:

<ul id="auction-type-filter">
<li>
<label class="btn" data-toggle="iconOnOff" data-icon-on="bb-home" data-icon-off="bb-home-o">
<input type="radio" name="auction-type"> <i class="bbIcon"></i>
</label>
</li>
<li>
<label class="btn" data-toggle="iconOnOff" data-icon-on="bb-setting" data-icon-off="bb-setting-o">
<input type="radio" name="auction-type"> <i class="bbIcon"></i>
</label>
</li>
</ul>
  1. 一旦页面加载 data-icon-off="off-icons-o"应该添加到所有<i class="bbIcon">例如。 <i class="bbIcon bb-setting-o">
  2. 单击单选按钮后,应添加带有填充图标的事件图标 <i class="bbIcon bb-setting">

这是我的 jQuery:

var bidderBlockIcon, bbIconOn, bbIconOff;

function fnButtonOutlineOnOff(el) {
bbIconOn = $(el).attr('data-icon-on');
bbIconOff = $(el).attr('data-icon-off');
bidderBlockIcon = $(el).find('.bbIcon');
}

$('[data-toggle="bbIconOnOff"]').each(function () {
// Adds outline Icons to all <i class="bbIcon"></i>
fnButtonOutlineOnOff(this);
bidderBlockIcon.addClass(bbIconOff);
}).click(function () {
fnButtonOutlineOnOff(this);
bidderBlockIcon.addClass(bbIconOn);
});

上面的代码只是添加了填充图标<i class="bbIcon bb-setting"></i>但在选择其他单选按钮时不会更改为 <i class="bbIcon bb-setting-o"></i>

最佳答案

一个更简单的方法是使用一个函数将它们全部关闭,然后打开change radio on

function allOff() {

$('[data-toggle="bbIconOnOff"]').each(function() {

var bbIconOn = $(this).data('icon-on');
var bbIconOff = $(this).data('icon-off');
$(this).find('.bbIcon').removeClass(bbIconOn).addClass(bbIconOff);

});

}

$('[name="auction-type"]').change(function() {

allOff();
var bbIconOn = $(this).parent().data('icon-on');
$(this).next('.bbIcon').addClass(bbIconOn);

});

allOff();

关于javascript - 更改事件按钮图标的单选按钮应为 OutlineIcon 或 FillledIcon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36599986/

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