如何仅使用Javascript在主体中添加数据
How to Add data in tbody using Javascript only
这是我的Javascript函数
function SaveCustomdata() {
var customName = document.getElementById("lblNAME").value;
var customEmail = document.getElementById("lblEmail").value;
var customContectNo = document.getElementById("lblContectNO").value;
var row = "";
row += '<tr><td>' + customName + '</td><td>' + customEmail + '</td><td>' + customContectNo + '</td></tr>';
document.getElementById("Customdata").appendChild(row);
}
附加数据的HTML代码:
<table>
<thead>
<tr>
<th style=" color:#01A0DF; padding-right:60px;">Name</th>
<th style=" color:#01A0DF; padding-right:70px;">Email</th>
<th style=" color:#01A0DF; padding-right:90px;">Contect/Mobile No</th>
<td>
<input type="button" id="btnclick" value="Add" onclick="AddRecord()" />
</td>
</tr>
</thead>
<tbody id="Customdata"></tbody>
</table>
出现错误:
0x800a139e - JavaScript运行时错误:Hierarchy Request error
使用innerHTML:
function SaveCustomdata() {
var customName = document.getElementById("lblNAME").value;
var customEmail = document.getElementById("lblEmail").value;
var customContectNo = document.getElementById("lblContectNO").value;
var row = "";
row += '<tr><td>' + customName + '</td><td>' + customEmail + '</td><td>' + customContectNo + '</td></tr>';
// get the current table body html as a string, and append the new row
var html = document.getElementById("Customdata").innerHTML + row;
// set the table body to the new html code
document.getElementById("Customdata").innerHTML = html;
}
给你一把小提琴。如果它对你有帮助,请告诉我们。
基本上你可以使用.innerHTML
附加字符串作为元素,因为这得到"由浏览器评估"。
否则就必须按照注释
相关文章:
- Knockout.JS,模板都是通过表单不添加数据的
- 如何使用Quickbase API和javascript检索、添加数据
- 添加数据属性及其值以使用纯javascript进行链接
- 向JavaScript对象文字添加数据
- GWT HashMap.put() 不向 HashMap 添加数据
- Meteor(JavaScript应用程序平台)|向用户帐户添加数据
- 从外部json代码向amcharts图表添加数据
- 无法在引导表中再次添加数据
- 如何在jQuery中的单个保存按钮上更新数据和添加数据
- 为selectize.js选项添加数据属性
- 动态添加数据时按数据属性查询JQuery选择器
- 弹出循环:添加数据时停止重复/三次应用/X
- 如何从javascript数组本身向chart-js添加数据
- ChartJS从字符串中添加数据
- JS-在JSON文件中插入、删除和添加数据
- 使用 Knockout.js 在文本区域中添加数据绑定和静态文本
- 动态添加数据时如何应用 ng 类 (?)
- 向 API 结果添加数据
- 如何使用 AngularJS 添加数据
- 使用 jQuery 添加数据属性