javascript - 从 jquery 将文本框值添加到 gridview,而不使用 C#

标签 javascript jquery

我有没有任何记录的 GridView ,我想使用 jQuery 将文本框值添加到 GridView 中,而不使用 C#。

enter image description here

最佳答案

如果 Id 属性是静态的(如果不是,请将 CssClass 属性添加到 GridView),那么您只需使用 jQuery 附加文本框

function addRecord() {
  var record = $('#newRecord').val();
  addRow(record);
  $('#newRecord').val('');
}

function addRow(value) {
  $('#GridView1 tbody').append('<tr><td>' + value + '</td></tr>');  
}
table, td, th {
  border: 1px solid;
  border-spacing: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Let's say that the gridview rendrer as table-->
<table id="GridView1">
  <thead>
  <tr>
    <th>Col 1</th>
  </tr>
  </thead>
  <tbody>
    <!-- It's empty because of no records-->
  </tbody>
</table>

<input id="newRecord" type="text" placeholder="Record to add" />
<!-- button with OnClientClick will render as onclick html attribute -->
<button onclick="addRecord()">Add a record</button>

关于javascript - 从 jquery 将文本框值添加到 gridview,而不使用 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41533960/

相关文章:

javascript - 良好的基于​​ JavaScript 的 HTML、CSS 和 JS 整理?

javascript - 在 JavaScript 中将样式应用于多个 Div

javascript - 导入组件的 Angular 7 动态变量名称

javascript - 如何从登录页面删除导航按钮

javascript - typescript /Angular 延迟每 X 秒和每个 X 元素继续循环

javascript - 动态加载 midi.js soundfonts

javascript - 同步数据会减慢应用程序

javascript - 如何从异步调用返回响应?

javascript - iframe 中的按钮使 div 显示在父级中

javascript - 在 AngularJS 中切换自定义排序图标