我正在使用Razor视图引擎生成一个使用此代码的RadioButton项目列表,我的css和Javascript是
.radioSelection
{
color: Green;
font-weight: bold;
}
$(document).ready(function () {
$("input[name=ScoreId]:radio").change(function () {
//How can i access the label span of current selection & reset the old selection
});
});
@foreach (var item in model)
{
<li class="radio clearfix ui-sortable-handle">
@Html.RadioButton("ScoreId", statement_item.Id, new { @class = "" })
<span class="lbl" >@statement_item.Statement</span>
</li>
}如何将类radioSelection设置为选定的radiobuttonList项,以及如何在选择新的无线电项时将旧项的选择重置为正常
发布于 2015-04-28 04:34:45
使用.next()函数获取所需的下一个元素span
$("input[name=ScoreId]:radio").change(function () {
$(':radio:checked').not(this).prop('checked',false)
$('li.radioSelection').removeClass('radioSelection'); //Reset selection
$(this).closest('li').addClass('radioSelection'); //Add class to list item
$(this).next('span') //Access span
});发布于 2015-04-28 04:34:06
试试- $(this).siblings('span.lbl')。
发布于 2015-04-28 04:45:20
试试这个:
$(document).ready(function () {
$("input[name=ScoreId]:radio").change(function () {
$(this).prop('checked', false); }) // make check only selected radio button and uncheck others
$('input:radio[name=ScoreId]').each(function () {
$(this).removeClass('className'); }) // remove the class from all radio buttons
}
$("input:radio[name=ScoreId]:checked").closest('li').addClass('radioSelection'); // add class only to selected radio button
$(input:radio[name=ScoreId]:checked).next('span'); // Access span of selected radio
});
}); https://stackoverflow.com/questions/29910387
复制相似问题