javascript - 如何用javascript编写html结构?

标签 javascript

如何在java脚本中编写html结构,

 <table>
<tr>
<td>
<form>
    <input  type="file"></input></td>
    <td><input type="submit"></input></td>
</form>
</table>

最佳答案

尝试使用以下内容并将其添加到 html 标记末尾之前。

<script>
var myForm = document.createElement("form");
myForm .setAttribute('method',"post");
myForm .setAttribute('action',"submit.php");

var myInput = document.createElement("input"); 
myInput .setAttribute('type',"file");
myInput .setAttribute('name',"somename");

var formSubmit = document.createElement("input"); 
formSubmit.setAttribute('type',"submit");
formSubmit.setAttribute('value',"Submit");

myForm .appendChild(myInput);
myForm .appendChild(formSubmit);

document.getElementsByTagName('body')[0].appendChild(myForm);

</script>

关于javascript - 如何用javascript编写html结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36215372/

相关文章:

javascript - 将在 Google 表格脚本中查找并删除特定行的循环

具有 ASP.NET API 凭据的 JavaScript XMLHttpRequest

javascript - IE7+ 的复选框/单选框样式

javascript - 当元素存在时,“classList”属性返回 null?

javascript - 获取json编码形式的信息

Javascript 闭包,函数总是指向数组中的最后一个对象

javascript - 如何为 LinkedIn、Twitter 和 Facebook 等社交平台设置特色图片以拉入预览?

javascript - Jquery 在悬停时 float

javascript - 在 Titanium 中将 View 创建为弹出窗口

javascript - 使用模态 Bootstrap 确认将不起作用