我需要将input.number
值传递给data-quantity
中button
的{{1}}属性。
我还需要相同div.add
的属性select#color
的{{1}}值。
有人能帮助我吗?
data-color
答案 0 :(得分:1)
由于你的代码中有Bootstrap classes,我假设你也有jQuery,那么你可以开始寻找你想要的东西:
// Triggers when the input value changes in any way
$('input#quantity').on('input',function() {
// Gets the input value
var value = $(this).val();
// This is how to change an element data-attribute
$('div.class > button').data("quantity", value);
});
有关详细信息,请参阅.on('input') jQuery事件以及.attr()和.data() jQuery方法。
<小时/> 要更改data-color
属性,它就完全相同:
// Triggers when you select an option
$('select#color').change(function() {
// Gets the current select value
var value = $(this).val();
// Now you just need to change the data-color attribute
// but you already know how to do it
});
有关详细信息,请参阅.change() jQuery事件。