我制作了以下表格:
<form action="search-engine/search.php">
<input id="words" name="q" class="form-control" type="text" placeholder="Buscar aquí" >
<div class="input-group-addon search-div">
<button type="submit" id="submitForm" class="btn-search">
<span class="fa fa-search fa-fw "></span>
</button>
</div>
</form>$("#words").autocomplete({
source: "autocomplete.php",
minLength: 2,
select: function(event, ui) {
//assign value back to the form element
if(ui.item){
$(event.target).val(ui.item.value);
}
//submit the form
$(event.target.form).submit();
}
});代码运行良好。Autocomplete正在运行,如果在做出选择后单击ENTER,则会提交表单。
我还想添加发送表单的可能性,当您与鼠标点击的选择,如谷歌。
我已经解决了改变:
$(event.target.form).submit();使用
document.getElementById("submitForm).click();有没有其他方法可以用Jquery做到这一点?
发布于 2016-04-08 00:18:17
问题在于您检索表单的方式。试试这个:
$(event.target).closest('form').submit();https://stackoverflow.com/questions/36481786
复制相似问题