【发布时间】:2017-06-04 18:41:32
【问题描述】:
我想制作像堆栈溢出标签一样的标签,但问题是 1-当我单击选项卡时它不起作用 2-当我单击输入时单击保存客户端的效果和 3-我想将标签发送为列表数组
<div class="row">
<div class="form-group">
<div class="col-md-12 col-sm-12">
<label>Address *</label>
<div class="target" contenteditable="true"></div>
<input type="text" id="clientAdd" name="address" value="" class="form-control required">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button type="submit" class="btn btn-3d btn-teal btn-xlg btn-block margin-top-30">
Save Client
</button>
</div>
</div>
这是jq代码
$("#clientAdd").keypress(function (e) {
if (e.which === 9 || e.which === 32 ) {
$(".target").append("<a href='#' class='tag'>" + this.value + "</a>");
var stringList = [];
stringList.push(this.value);
this.value = "";
}
});
这是css代码
.tag {
color: #3E6D8E;
background-color: #E0EAF1;
border-bottom: 1px solid #b3cee1;
border-right: 1px solid #b3cee1;
padding: 3px 4px 3px 4px;
margin: 2px 2px 2px 0;
text-decoration: none;
font-size: 90%;
line-height: 2.4;
white-space: nowrap;
}
.tag:hover {
background-color: #c4dae9;
border-bottom: 1px solid #c4dae9;
border-right: 1px solid #c4dae9;
}
【问题讨论】:
-
这 3 个问题你没有表现出任何你自己的努力,基本你的要求是让我们编码它。
-
周围有许多脚本可以为您做到这一点。您的主要问题是在每个按键事件中初始化一个新数组
-
@Carsten Løvbo Andersen 我解决了大部分问题,但我唯一没有解决的问题是我想创建标签字符串数组以在单击保存客户端 btn 时发送
标签: javascript jquery html css arraylist