【发布时间】:2017-09-07 20:17:37
【问题描述】:
我无法输入下一个输入字段,即在逗号输入上创建文本的第一个字段,它似乎工作正常,但 focus 不工作
这里是代码
- 在第一个字段中输入内容,点击逗号
- 尝试移至下一个输入字段,焦点不起作用
$('#tags input').on('focusout', function() {
var txt = this.value.replace(/[^a-zA-Z0-9\+\-\.\#]/g, ''); // allowed characters list
if (txt) $(this).before('<span class="tag">' + txt + '</span>');
this.value = "";
this.focus();
}).on('keyup', function(e) {
if (/(188|13)/.test(e.which)) $(this).focusout();
event.preventDefault(e);
});
.form-group{float:left; width:100%; margin-bottom:15px;}
.form-group > input{padding:6px 12px; width:100%;}
.tag{background:#ccc; padding:2px 4px; display:inline-block; margin-right:5px; margin-bottom:5px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="form-group" id="tags" >
<label for="submittedby">Add CC</label>
<input type="text" class="form-control" value="" placeholder="Add Email Address">
</div>
<div class="form-group" >
<label for="submittedby">Other</label>
<input type="text" class="form-control" value="" placeholder="Add Email Address">
</div>
【问题讨论】:
-
因为你在
focusout事件上做focus(),导致重新关注同一个元素
标签: javascript jquery html forms