我做了以下表格:
<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();
}
});
代码效果很好。自动填充正在运行,如果在进行选择后单击“输入”,则表示已提交。
我还希望添加用鼠标点击所选内容时发送表单的可能性,例如Google。
我已经解决了改变:
$(event.target.form).submit();
用
document.getElementById("submitForm).click();
还有另一种方法可以使用Jquery吗?
答案 0 :(得分:0)
问题在于您检索表单的方式。试试这个:
$(event.target).closest('form').submit();