创建一个系统以在Javascript中添加产品标签



我正在开发自己的电子商务。我想创建一个如图所示的界面,为产品添加标签。我希望当添加标签时,它会显示为图像。

图像链接

请告诉我解决这个问题的方法好吗?一些使用HTML或Javascript实现它的提示或示例。

我不确定这是否是您所需要的,但您可以从中开始。

$( "#add" ).click(function() {
var x = document.getElementById("tags");
var li = document.createElement("LI");
var a = document.createElement("A");
var temp=x.appendChild(li);
temp=temp.appendChild(a);
temp.innerHTML=document.getElementById("name").value;
temp.setAttribute("class","tag");
});
body {
font: 12px/1.5 'PT Sans', serif;
margin: 25px;
}
.tags {
list-style: none;
margin: 0;
overflow: hidden; 
padding: 0;
}
.tags li {
float: left; 
}
.tag {
background: #eee;
border-radius: 3px 0 0 3px;
color: #999;
display: inline-block;
height: 26px;
line-height: 26px;
padding: 0 20px 0 23px;
position: relative;
margin: 0 10px 10px 0;
text-decoration: none;
-webkit-transition: color 0.2s;
}
.tag::before {
background: #fff;
border-radius: 10px;
box-shadow: inset 0 1px rgba(0, 0, 0, 0.25);
content: '';
height: 6px;
left: 10px;
position: absolute;
width: 6px;
top: 10px;
}
.tag::after {
background: #fff;
border-bottom: 13px solid transparent;
border-left: 10px solid #eee;
border-top: 13px solid transparent;
content: '';
position: absolute;
right: 0;
top: 0;
}
.tag:hover {
background-color: crimson;
color: white;
}
.tag:hover::after {
border-left-color: crimson; 
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1>Tags</h1>
<input type="text" id="name" name="name" >
<button id="add">Add</button>

<h2>Example</h2>
<ul id="tags" class="tags">
<li><a href="#" class="tag">HTML</a></li>
<li><a href="#" class="tag">CSS</a></li>
<li><a href="#" class="tag">JavaScript</a></li>
</ul>