我有下表 -
<tbody>
@for (int i = 0; i < Model.Count; i++)
{
<tr>
<td>
@Html.CheckBoxFor(modelItem => modelItem[i].ShouldImport, new { @class = "sid", @onclick = "DisplayDetailedInfo(this)" })
</td>
<td>
@Html.DisplayFor(modelItem => modelItem[i].Name)
@Html.HiddenFor(modelItem => modelItem[i].Name)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem[i].AccountNumber)
@Html.HiddenFor(modelItem => modelItem[i].AccountNumber)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem[i].AccountType)
@Html.HiddenFor(modelItem => modelItem[i].AccountType)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem[i].AccountStatus)
@Html.HiddenFor(modelItem => modelItem[i].AccountStatus)
</td>
<td>
@Html.CheckBoxFor(modelItem => modelItem[i].IsLatePayment)
</td>
</tr>
}
我的Javascript功能如下 -
function DisplayDetailedInfo(data) {
console.log(data);
var vval = $(data).val();
var anotherval = $(this).is(':checked')
console.log(anotherval);
if (anotherval)
{
console.log("Hi");
}
}
我需要帮助,虽然我正在检查复选框,但为什么我的价值是假的。我是razor和Jquery的新手,需要帮助。
答案 0 :(得分:1)
您的案例中的关键字this
正在返回window
,因此您必须将其替换为data
,如下所示:
function DisplayDetailedInfo(data) {
console.log(data);
var vval = $(data).val();
var anotherval = $(data).is(':checked');
console.log(anotherval);
if (anotherval)
{
console.log("Hi");
}
}