jquery - Jquery动态添加行的复选框总是返回false
问题描述
我正在使用 jquery 在下拉更改事件上动态添加行。行包含复选框、TextArea 和 Dropdown。所有控件都与模型的属性绑定。Checkbox 还绑定了 Model 的 bool 属性。在提交表单时,控制器接收模型,其他控件(如 TextArea 和下拉列表)在表单中输入了值,但尽管选中了复选框,但复选框属性始终为 false。
这就是 HtmlHelper 类用于绑定模型的方式。
<tr>
<td>
@Html.CheckBoxFor(model => model.FunctionalRequirementsList[i].isSelected, new { @class = "checkbox" })
@Html.HiddenFor(model => model.FunctionalRequirementsList[i].FunctionalRequirementId)
</td>
<td>
@Html.TextAreaFor(model => model.FunctionalRequirementsList[i].FunctionalRequirement, 5, 80, new { @class = "text form-control col-md-10", style = "background-color:#fcf999;max-width:100%;height:50px;", ReadOnly = "true" })
</td>
<td>
@Html.DropDownListFor(model => model.FunctionalRequirementsList[i].DefaultPriorityId, new SelectList(Model.FunctionalRequirementsList[i].ApllicabilityOptions, "Value", "Text", Model.FunctionalRequirementsList[i].DefaultPriorityId), new { @class = "form-control col-md-1" })
</td>
</tr>
动态加法的jquery代码:
var oldFRSelected_Id = $trlast.find("input[type='checkbox'][id*='isSelected']").attr('id')
var oldFRSelected_Id_Slice = oldFRSelected_Id.split('_');
var newFRSelected_Id = oldFRSelected_Id_Slice[0] + "_" + (i + 1) + "__" + oldFRSelected_Id_Slice[3]
var newFRSelected_name = oldFRSelected_Id_Slice[0] + "[" + (i + 1) + "]." + oldFRSelected_Id_Slice[3]
$trclone.find("input[type='checkbox'][id*='isSelected']").attr('id', newFRSelected_Id);
$trclone.find("input[type='checkbox'][id*='isSelected']").attr('name', newFRSelected_name);
解决方案
推荐阅读
- oracle - Like 运算符或任何其他可以使用的运算符
- php - 删除已定义产品类别组的 WooCommerce 支付网关
- javascript - 文本之间的空间如何根据字体大小缩放?
- android - 从改造 2.6.2 更新到改造 2.9.0 后 OkHttpClient.Builder() 中的 java.lang.NoSuchMethodError
- arrays - Redux 存储不更新数组而是抛出错误状态。列表不可迭代
- javascript - 如何将我的输入值复制到 React 中的下一个输入?
- python - 如何强制一维信号具有 2 个最小值?
- java - “不兼容的类型:void 不能转换为 PLayer”这是什么意思?
- excel - 在 VBA 中更改用户窗体框架字体大小
- node.js - 如何使用 Nestjs 建立多语言网站?