简体   繁体   English

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

[英]How to add div field dynamically in to a html page?

i tried to add a div field dynamically on clicking button but i am not getting response.我试图在点击按钮时动态添加一个 div 字段,但我没有得到响应。 here is my code.这是我的代码。

<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>

Here Is My Js Code这是我的 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>');
  });
});

Try this尝试这个

<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>

you should delete # on your HTML script你应该在你的 HTML 脚本中删除 #

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

you can source this on google你可以在谷歌上找到这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM