我对 JS 还很陌生,所以我有点困惑为什么这不起作用。 基本上我使用的是 geocomplete jQuery用坐标和地址填充表单的插件。然后,一旦用户选择了目的地,我就想提交表格。
<form action="search.php" method="post" id="searchForm">
<input id="geocomplete" type="text" placeholder="Where are you going to?" size="35" />
<input name="lat" type="hidden" value="">
<input name="lng" type="hidden" value="">
<input name="formatted_address" type="hidden" value="" id="address">
</form>
这将是我调用以启动表单插件(有效)的脚本,以及在插件更改地址值后提交表单的脚本:
<script type="text/javascript">
window.onload= function () {
if(window.addEventListener) {
document.getElementById('address').addEventListener('change', doIt, false);
} else if (window.attachEvent){
document.getElementById('address').attachEvent("onchange", doIt);
}
function doIt(){
document.getElementById("searchForm").submit();
}
}
$("input").geocomplete({ details: "form" });
</script>
我不明白为什么这行不通,因为值确实发生了变化。非常感谢!
最佳答案
change
事件仅在通过直接用户输入发生更改时触发,而不是在脚本更改输入值时触发。
按照您已链接到的页面上的描述使用该插件提供的事件。
关于javascript - 根据建议选择提交地理完整表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28658951/