javascript - 如何将div字段动态添加到html页面中?

标签 javascript jquery html css jquery-append

我试图在单击按钮时动态添加一个 div 字段,但我没有得到响应。这是我的代码。

<div id="#para">
  <tr class="divider"></tr>
  <tr>
    <td><input type="text" placeholder="Enter Medicin Name" style="width:80%;height:30px;"></td>
    <td><input type="file" </td>
    <td><input type="time" placeholder="Enter Medicin Time"></td>
    <td><input type="date" placeholder="Enter Start Date"></td>
    <td><input type="date" placeholder="Enter End Date"></td>
  </tr>
  <tr class="divider"></tr>
</div>
<button type="submit" class="button" id="#btn1" value="Submit"><img src="images/plus.png"> Add More Notification</button>

这是我的JS代码

$(document).ready(function(){
  $("#btn1").click(function(){
    $("#para").append('  <tr class="divider"></tr> <tr class="notification-row"><td><input type="text" placeholder="Enter Medicin Name" style="width:80%;height:30px;"></td>  <td><input type="file" </td> <td><input type="time" placeholder="Enter Medicin Time"></td> <td><input type="date" placeholder="Enter Start Date"></td><td><input type="date" placeholder="Enter End Date"></td> </tr><tr class="divider"></tr>');
  });
});

最佳答案

试试这个

<div id="para">
  <tr class="divider"></tr>
  <tr>
    <td><input type="text" placeholder="Enter Medicin Name" style="width:80%;height:30px;"></td>
    <td><input type="file" </td>
    <td><input type="time" placeholder="Enter Medicin Time"></td>
    <td><input type="date" placeholder="Enter Start Date"></td>
    <td><input type="date" placeholder="Enter End Date"></td>
  </tr>
  <tr class="divider"></tr>
</div>
<button type="submit" class="button" id="btn1" value="Submit"><img src="images/plus.png"> Add More Notification</button>

你应该在你的 HTML 脚本中删除#

in HTML (id) = jQuery (#) in HTML (class) = jQuery (.)

你可以在谷歌上找到这个

关于javascript - 如何将div字段动态添加到html页面中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40057241/

相关文章:

javascript - 让我的弹出窗口可以拖动到任何地方?

javascript - 键入时将数据插入数据库

html - 如何创建面板选项卡?

html - CSS 继承 - 为什么 'later' 声明被 'earlier' 声明覆盖?

JavaScript 在 Mobile Safari 中无法运行

javascript - 使用nodejs/express 出现意外的换行符

javascript - react.js ReactComponent 不提供 setState()?

Javascript - 防止右键单击滚动条以查看页面源代码

javascript - 自定义指令在 Angular js 中不起作用

javascript - 在 map 或 forEach 中使用调用函数