作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 razor View 中有一个表,该表包含一些如下所示的 Html 控件:-
<table style="text-align: center; width: 680px; background-color: White;" rules="all" id="tableId">
<tr>
<td style="width: 20px;"></td>
<td>
<label>
Campaign Name</label>
</td>
<td>
<label>
Valid Date From</label>
</td>
<td>
<label>
Valid Date To</label>
</td>
<td>
<label>
Is Active</label>
</td>
<td>
<label>
ContractPDF</label>
</td>
<td>
<label>
Browse Contract</label>
</td>
</tr>
<tr>
<td>
@Html.HiddenFor(m => m.Customer_ID)
</td>
<td class="trBorder">
@Html.TextBoxFor(m => m.Customer_Name)
</td>
<td class="trBorder">
@Html.TextBoxFor(m => m.ValidFrom, new { @class = "datepicker" })
</td>
<td>
@Html.TextBoxFor(m => m.ValidTo, new { @class = "datepicker" })
</td>
<td>
@Html.CheckBox("gridChkCampaignIsActive", m => m.IsActive)
</td>
<td>
@Html.TextBoxFor(m => m.ContractDocumentPath)
</td>
<td>
@Html.ActionLink("Browse", "FileUpload")
</td>
</tr>
</table>
添加客户按钮
<input type="button" value="Add Customer" name="btnAddCustomer" id="btnAddCustomer" style="margin-left: 20px;"/>
我的问题是当我点击 "Add Customer"
时,我希望这个表格像网格控件一样按钮,将在网格控件中添加一个空白行。
请帮助我!
我们将不胜感激
最佳答案
它太简单了,为每个元素分配一个 id 并访问值,然后填充一个表
喜欢
@Html.TextForFor(m=>m.name, new {@class="form-control", id="name"})
//then dynamically table to be populated via javascript
<table id="tbl">
<thead></thead>
<tbody></thead>
</table>
<input type="button" value="Add Customer" name="btnAddCustomer" id="btnAddCustomer" style="margin-left: 20px;"/>
//assume that u have assign id to text boxes like a, b, c, and ,so on..
<script>
$.(#btnAddCustomer).click(function () {
var pc = $("#pcode").val();
var p = $("#a").val();
var q = $("#b").val();
var e = $("#c").val();
var rows = '';
rows += "<tr>"
rows += "<td>" + p + "</td>"
rows += "<td>" + q + "</td>"
rows += "<td>" + r + "</td>"
rows += "</tr>";
$("#tbl tbody").append(rows);
})
</script>
关于javascript - 如何在 MVC4 中使用 Razor View 在表中动态行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18830401/
我是一名优秀的程序员,十分优秀!