我有一个下拉列表,两个文本框,添加按钮和一个表格。我需要做两件事。第一件事是,用下拉列表的选定文本填充一个文本框,用户将在第二个文本框中输入值。我可以为这个部分找到一个解决方案,并且它已经完成了。第二部分是,我需要在javascript或jquery中单击按钮,将这两个文本框中的文本添加到HTML表中。使用按钮单击和文本框文本时,表格行必须增加1。谁能帮帮我。我对脚本是个新手,这就是为什么我觉得很难做到这一点。提前谢谢。下面是我已经做过的事情。
两个文本框并添加带有表的按钮。
<div class="form-group">
<div class="col-md-2">
</div>
<div class="col-md-2">
@Html.Editor("CompTxt", new { htmlAttributes = new { @class = "form-control", @readonly = "readonly", @style = "width:80px" } })
</div>
<div class="col-md-2">
@Html.Editor("ValTxt", new { htmlAttributes = new { @class = "form-control", @style = "width:80px" } })
</div>
<div class="col-md-2">
<input class="btnAdd btn btn-primary" style="width:80px" type="button" name="name" value="Add" onclick="insertRow();"/>
</div>
</div>
<div class="form-group">
<div class="col-md-2"></div>
<div class="col-md-7">
<table id="CompTable" class="table table-striped">
<thead>
<tr>
<th>
@Html.DisplayName("Description")
</th>
<th>
@Html.DisplayName("Value")
</th>
<th>
@Html.DisplayName("Action")
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
@Html.Editor("CompDes", new { htmlAttributes = new { @class = "form-control", @readonly = "readonly", @style = "width:80px" } })
</td>
<td>
@Html.Editor("Val", new { htmlAttributes = new { @class = "form-control", @style = "width:80px" } })
</td>
<td>
@Html.ActionLink("Remove", "RemoveRow")
</td>
</tr>
</tbody>
</table>
</div>
</div>将下拉文本复制到文本框的Javascript代码。
<script>//copy dropdown text to textbox
$(document).ready(function () {
$('#ddlCompositions').change(function () {
$('#CompTxt').val($(this).find("option:selected").text())
});
});
</script>发布于 2018-08-10 15:07:41
您可以在下一篇文章中找到答案。
单击事件处理在表格Add table row in jQuery
How to select and change value of table cell with jQuery?或How to Handle Button Click Events in jQuery?
https://stackoverflow.com/questions/51779585
复制相似问题