我找到了这段代码:
var checkboxes = $('input[type=checkbox]');
checkboxes.on('change', function() {
$('#divfilter').text(function() {
return checkboxes.filter(':checked').map(function() {
return this.name;
}).get()
.join(', ') + '.';
});
});<input type="checkbox" name="barbecue" id="barbecue" value="oui" class="barbecue" />
<input type="checkbox" name="handicap" id="handicap" value="oui" class="handicap" />
<input type="checkbox" name="animaux" id="animaux" value="oui" class="animaux" />
<div id="divfilter"></div>
它工作得很好,但我需要在data -namevar=“here”中显示数据:
<button
data-namevar="I NEED CHECKBOX CHECKED SHOW HERE"
class="add-to-cart btn_1 gradient medium full-width">Add to cart <i class="icon_bag_alt"></i>
</button>该怎么做呢?
发布于 2021-07-28 17:18:08
你能试试这个吗?
var checkboxes = $('input[type=checkbox]');
checkboxes.on('change', function() {
$('#divfilter').text(function() {
return checkboxes.filter(':checked').map(function() {
return $(this).attr('data-namevar');
}).get()
.join(', ') + '.';
});
});发布于 2021-07-29 23:15:58
现在,如何在我的html中准确地显示这些数据呢?
<button
data-namevar="I NEED CHECKBOX CHECKED NAMES SHOW HERE">
Add to cart
</button>https://stackoverflow.com/questions/68564685
复制相似问题