【发布时间】:2013-06-05 08:51:02
【问题描述】:
我在不同网站的帮助下编写了以下代码。一段sn-p的代码如下:
function getLocation()
{
var visitorGeolocation = new geolocate(false, true, 'visitorGeolocation');
//Check for cookie and run a callback function to execute after geolocation is read either from cookie or IPInfoDB API
var callback = function()
{
var city=document.getElementById("city");
city.value = visitorGeolocation.getField('cityName');
alert('Visitor city name : ' + visitorGeolocation.getField('cityName'))
};
visitorGeolocation.checkcookie(callback);
}
</script>
</head>
<body onload="getLocation()">
<form name="frm" method="post" action="result.jsp?page=1">
<input type="text" name="myQuery">
<input name="city" id="city" type="hidden" value="city">
<input type="submit" name="submit" value="Submit">
</form>
我想在提交表单时静默传递 city 的值,以便我可以在结果页面中获取 city 的值。这就是为什么我将其类型设置为“隐藏”。但是我无法理解如何在提交表单时设置 city 的值,因为我在回调函数中获取了 city 的值,如上所示。我不知道该怎么做。
我是网络编程新手。我对回调函数知之甚少。因此,如果有人帮助我解决这个问题,我将不胜感激。谢谢你。
【问题讨论】:
-
Excuse but alert('Visitor city name : ' + visitorGeolocation.getField('cityName')) 打印城市正确吗?
-
是的,先生,它打印的城市是正确的。
标签: javascript html callback forms http-post