我不明白为什么我的onsubmit处理程序在提交时没有被触发。它在js文件中定义,并且是html文件所必需的。像这样:
Locale locale = new Locale("en_US");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
SettingActivity.this.getApplicationContext().getResources().updateConfiguration(config, null);
langd.dismiss();
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
和GMaps.ejs
GMaps.js
window.onload = function(){
(function initMap() {
var myLatLng = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: myLatLng
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Hello World!'
});
})();
function gsubmit(event){
event.preventDefault();
console.log("hi");
}
};
这只是使用gmap的一个基本示例,我无法让表单识别我的提交处理程序
答案 0 :(得分:2)
这是一个范围问题。
由于gsubmit
位于您的window.onload
匿名函数中,因此在您提交表单时,未找到名为gsubmit的函数。
试试这个:
window.onload = function(){
(function initMap() {
var myLatLng = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: myLatLng
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Hello World!'
});
})();
}
function gsubmit(event){
event.preventDefault();
console.log("hi");
}