我在Semantic UI modal中有一个Twitter Typeahead。期望的行为是用户可以从预先输入的内容中选择一些东西,并且在确认他们的选择之前仍然在模态中工作。但是,如果用户单击选择,则模式会提前关闭。这仅在单击时发生;如果用户使用箭头键来选择一个选项,或者使用来完成,那么模态将根据需要保持打开状态。 Tab
我制作了一个JSFiddle来演示这个问题。下面的最小代码摘要:
索引.html:
<div id="pick-user-modal" class="ui modal"><i class="close icon"></i>
<div class="header">Select user</div>
<div class="content">
<input type="text" id="user-field" />
</div>
<div class="actions">
<a id="send-request" class="ui green button">Select user</a>
</div>
</div>
<a class="green ui button" id="show-pick-user-modal">Select user</a>
主.js:
$('#pick-user-modal').modal();
$('#show-pick-user-modal').click(function () {
$('#pick-user-modal').modal('show');
});
var $users = $('#user-field');
$users.typeahead({
name: 'users',
local: ["Andy","Betty","Charles","Dotty","Elton","Fred","Grace","Harriet",
"Ichabod","Jenny","Karen","Louise","Michael","Nathan","Oswald",
"Patricia","Quendy","Robert","Sylvia","Thomas","Ursula","Vivian",
"Wendy","Xavier","Yvonne","Zachary"]
});
function setUser(e,d){
alert(d.value);
}
$users.on('typeahead:selected',setUser);
$users.on('typeahead:autocompleted',setUser);
我试过false
从返回setUser
并打电话e.preventDefault()
,但都没有解决问题。