我是Java语言的DRYING代码新手。有人可以帮我干燥此javascript代码
这是获取数据的地方
<div class="form-group">
@Html.LabelFor(model => model.eMP.EMPNO, "Employee Number", htmlAttributes: new { @class = "control-label" })
@Html.EditorFor(model => model.eMP.EMPNO, new { htmlAttributes = new { @class = "form-control", @id = "EMPNO" } })
@Html.ValidationMessageFor(model => model.eMP.EMPNO, "", new { @class = "text-danger" })
</div>
这是应该去的值
<div class="form-group">
@Html.LabelFor(model => model.Emp_educ.EMPNO, "EMPNO", htmlAttributes: new { @class = "control-label" })
@Html.EditorFor(model => model.Emp_educ.EMPNO, new { htmlAttributes = new { @class = "form-control", @id = "EMPNOEDUC", readOnly = "readonly" } })
@Html.ValidationMessageFor(model => model.Emp_educ.EMPNO, "", new { @class = "text-danger" })
到目前为止,这是我的代码,我目前正在尝试最小化代码的冗余。有什么办法可以烘干此代码?
$(document).ready(function () {
$("#EMPNOEDUC").val($("#EMPNO").val());
$("#EMPNOJOBHIST").val($("#EMPNO").val());
$("#EMPNOREFERENCE").val($("#EMPNO").val());
$("#EMPNOLICENSES").val($("#EMPNO").val());
});
将类别添加到输入中,然后可以在一行中设置值$("#EMPNO").val()
您可以在组合的jQuery选择器中列出目标ID,如下所示: