0

我有一个下拉列表:

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

和一个复选框:

@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 字符串?我究竟做错了什么 ?

4

2 回答 2

1

尝试

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

你错过"id属性

于 2012-09-04T13:55:15.773 回答
0

用“#”代替“。”

$('#slotDDL_')
于 2012-09-04T13:42:19.370 回答