首页 > 解决方案 > 用js和dom appendChild添加输入标签好像没有边距

问题描述

当我在 js 脚本中添加带有 DOM 的输入标签时,appendChild()它们似乎没有边距,因为它们之间没有分隔。已写入 html 文件的输入标签具有这种分隔。元素检查器说它们都具有相同的样式。

js脚本:

document.body.appendChild(document.createElement("input"));

我不知道如何用谷歌搜索这个问题,所以我在这里问,发生了什么事,如何在 js 脚本中解决这个问题?

标签: javascripthtml

解决方案


您可以按如下方式添加边距:

let inp = document.createElement("input");
inp.style.margin='4px';
document.body.appendChild(inp);
inp = document.createElement("input");
inp.style.margin='4px';
document.body.appendChild(inp);


推荐阅读