繁体   English   中英

在javascript中添加HTML代码段?

[英]Adding an html code snippet to javascript?

我正在为网站使用JavaScript插件,必须在其中将表单添加到页面的特定面板中。 我想知道是否有任何方法可以将html文件(包含表单的html代码)导入/读取到javascript文件中,而不是创建一堆HTML元素来创建表单。

如果使用jQuery,则可以使用appendinsertAfter和类似方法append HTML作为字符串插入(请注意,模板字符串语法仅在兼容ECMAScript6的浏览器上有效)。

$('#addForm').click(function() { // execute the following with #addForm is clicked
  $('#formPanel').append( // add the following to the innerHTML of #formPanel
    // backtick starts a template string
    `
    <form action='sumbit.php' method='POST'>
      First name: <input name='first'>
      Last name: <input name='last'>
      <input type='submit'>
    </form>
  `);
});

暂无
暂无

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

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