i have 3 radio buttons.what i need to do is that when one radio button is selected so i need to apply my css class name "line" on the text after it like
<span> <input type="radio" name="group1" value="Milk"> Milk </span>
我需要在 Milk 上应用我的课程,并且当用户选择其他单选按钮时,相同的课程适用于其他单选按钮文本,但从前一个单选按钮文本中删除课程。这就是我尝试过的
<style type="text/css">
.line{
text-decoration: line-through;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$("input[type='radio']").change(function(){
if($(this).is(':checked'))
//i wana do this
$(this).addClass('line');
//if another is selected so do this
$(this).removeClass('line');
});
});
<div>
<span> <input type="radio" name="group1" value="Milk"> Milk </span> </br>
<span> <input type="radio" name="group1" value="Butter"> Butter </span> </br>
<span> <input type="radio" name="group1" value="Cheese"> Cheese </span> </br>
<hr>
</div>