【发布时间】:2021-08-31 10:56:45
【问题描述】:
我有以下输入,例如两个值
<input id="input" type="text" />
let input = document.getElementById('input');
console.log(input);
input.value = 'John Peter';
我希望这个输入值在我的输入上方显示为筹码,但我找不到方法 - 如何设置我输入中的值的样式。我需要这样做,因为我有自动完成功能,当我点击输入时,会打开额外的窗口,我可以在其中选择选项。
当我选择某个选项时,它需要在输入上方显示为 CHIP。
类似
https://material.angular.io/components/chips/examples
所以我的芯片样式看起来像这样
.chip {
display: inline-block;
padding: 0 18px;
font-size: 14px;
border-radius: 25px;
background-color: #e0e0e0;
font-weight: 600;
min-height: 32px;
display: flex;
align-items: center;
color: rgba(0, 0, 0, 0.87);
transition: 0.2s all ease;
width: 60px;
}
.chip img {
float: left;
margin: 0 10px 0 -25px;
height: 32px;
width: 32px;
border-radius: 50%;
}
.closebtn {
color: #888;
font-weight: bold;
font-size: 20px;
cursor: pointer;
background-color: #0a0a0a;
border-radius: 50%;
width: 14px;
height: 14px;
color:#ffffff;
position: relative;
color: rgba(0,0,0,.87);
opacity: .5;
margin-left: 10px;
}
.close-icon {
position: absolute;
top: 55%;
left: 50%;
transform: translate(-50%, -60%);
color:#704e4e;
}
.closebtn:hover {
color: #000;
}
<div class="chip">
<span class="chip-text">Peter</span>
<div class="closebtn"><span class="close-icon">×</span>
</div>
</div>
如何使输入 John and Peter 上的值在我的输入上显示为两个 chips?
【问题讨论】:
-
您应该使用其他元素。仅使用 html 输入是不可能的
标签: javascript html css