【发布时间】:2021-01-21 08:58:32
【问题描述】:
我正在尝试使用 JavaScript like this 为数组中的每个元素设置单独的背景和边框。到目前为止,我所做的output如下。当我向数组中添加一个新元素时,它会拉伸背景。
let skills = [];
function displayname() {
console.log(document.getElementById("namehere").value);
x = document.getElementById("namehere").value;
skills.push(x);
console.log(skills)
document.getElementById("skill-set").innerHTML = skills
document.getElementById("skill-set").style.border = "1px solid blue";
document.getElementById("skill-set").style.backgroundColor = "yellow";
document.getElementById("skill-set").style.padding = "5px";
document.getElementById("skill-set").style.display = "inline-block";
document.getElementById('namehere').value = " ";
}
<label>Enter the skills: </label><br>
<input type=t ext id="namehere" onchange="displayname()">
<div id="skill-set"></div>
【问题讨论】:
-
你试过循环元素来设置css吗?
标签: javascript html jquery css django