私はいくつかのラジオボタンを持っています。jqueryの入力属性に基づいてクラスを追加する方法は?
入力された入力ラジオボタンにクラスを適用するために使用できるjqueryステートメントのタイプは何ですか?
私も付属している私のjsfiddle
https://jsfiddle.net/2Lbbf1b4/1/
$(function() {
$('label.radio-inline input').on('change', function() {
var name = $(this).attr('name');
if (true === $(this).prop('checked')) {
$('[name=' + $(this).attr('name') + ']').parent().removeClass('radio-select');
$(this).parent().addClass('radio-select');
}
});
});
<label class="radio-inline radio-style">
<input type="radio" checked="checked" name="test1" value="1" class="radio-style">
</label>
<label class="radio-inline radio-style">
<input type="radio" name="test1" value="2">
</label>
<br>
<label class="radio-inline radio-style">
<input type="radio" checked="checked" name="test" value="1" class="radio-style">
</label>
<label class="radio-inline radio-style">
<input type="radio" name="test" value="2">
</label>
チェーン' .change() 'や' .trigger( "変更") ':
フィドルをチェック) 'https://jsfiddle.net/2Lbbf1b4/3/ – guest271314