我有一个由下拉列表选择项目生成的JavaScript动态表格。 我的表格包含复选框,显示名称的列和输入数量的列。 我想要的是让所有文本框禁用untel其行被检查。 这是我的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
@ ProgrammerV5我编辑了我的帖子,谢谢 – oumaima
谢谢,但这不是呈现的HTML,它只是一个视图。我发布了一个解决方案,可以帮助您在自己的代码中找到问题,希望它有所帮助! – ProgrammerV5