在Jquery中构建CheckBox的Id

时间:2012-09-04 13:39:18

标签: jquery

我有一个DropDownList:

 @Html.DropDownList("name", (IEnumerable<SelectListItem>)SlotList[counter], new { id = "slotDDL_" + @item.ResourceID, tid = @item.ResourceID, @class = "slotDDL_ text white" })

和CheckboxFor:

@Html.CheckBoxFor(modelItem => item.IsSelected, new { @class = "boxcheck_", id = @item.ResourceID })

执行此操作时:

 $('.slotDDL_').change(function () {
            var resId = $(this).attr("tid");
            IsSelected = 'boxcheck_' + resId;
            alert($('#' + resId).attr("checked"));
      });

我得到以下内容:

alert($(this).attr("tid"))====>505
alert(IsSelected)====> boxcheck_505
alert($('#' + resId).attr("checked"))===>undefined

问题: 如何成功构建我的Id字符串?我究竟做错了什么 ?

2 个答案:

答案 0 :(得分:1)

尝试

@Html.CheckBoxFor(modelItem => item.IsSelected, new { @class = "boxcheck_", id = "@item.ResourceID" })

"属性

错过了id

答案 1 :(得分:0)

把'#'代替'。'

$('#slotDDL_')