【发布时间】:2017-04-05 21:27:34
【问题描述】:
我有一个由 javascript 从下拉列表中选择的项目生成的动态表。 我的表格包含一列复选框,一列显示名称和一列输入数量。 我只想让所有文本框都被禁用,直到它的行被检查。 这是我的 javascript 代码,禁用对我不起作用。
<script>
$(function () {
$("#ProduitID").change(function () {
$.get("/Demandes/GetGabarit", { produit: $("#ProduitID").val() }, function (data) {
$("#Gabarit").empty();
$.each(data, function (index, row) {
$("#Gabarit").append($("<tr>").append("<td>" + "<input type=checkbox name= gabarit class=Check value='" + row.CodeBarre + "'/>" + "</td>"
+ "<td>" + row.Designation + "</td>"
+ "<td>" + "<input type=text style=width:50px; name=Qt class=Quantite/>" + "</td>"
));
});
})
});
});
$(document).ready(function () {
$('#checkBoxAll').click(function () {
if ($(this).is(":checked")){
$('.Check').prop('checked', true);
$('.Quantite').prop('disabled', false);
}
else{
$('.Check').prop('checked', false);
$('.Quantite').prop('disabled', true);
}
});
});
</script>
查看:
<div class="form-group">
@Html.LabelFor(model => model.Produit, "Produit", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(p => p.CodeBarre, ViewBag.Produit as SelectList, "Sélectionner un produit", new { id = "ProduitID", @class = "form-control" })
@Html.ValidationMessageFor(model => model.Produit, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CodeBarre, "Gabarit", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<table class="table table-striped">
<thead>
<tr>
<th width="25%"><input type="checkbox" id="checkBoxAll" /></th>
<th width="25%">@Html.DisplayNameFor(model => model.Designation)</th>
<th width="25%">@Html.DisplayNameFor(model => model.Quantite)</th>
</tr>
</thead>
<tbody id="Gabarit">
<tr>
<td class="Designation"></td>
<td class="Quantite" ></td>
<td class="Check"></td>
</tr>
</tbody>
</table>
@Html.ValidationMessageFor(model => model.CodeBarre, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Submit" class="btn btn-default" />
</div>
</div>
谢谢。
【问题讨论】:
-
能否请您也发布此 JS 附带的 HTML?发布一个它不起作用的 JSFiddle 比仅仅发布一段代码更有帮助,这样我们就可以解决您遇到的小问题,而不是为您重新创建整个代码。这样你的问题就会得到更多的答复。
-
@ProgrammerV5 我编辑了我的帖子,谢谢
-
谢谢,但这不是呈现的 HTML,它只是一个视图。我发布了一个解决方案,可以帮助您在自己的代码中找到问题,希望对您有所帮助!
标签: javascript c# jquery asp.net asp.net-mvc