基本javascript错误
本文关键字:错误 javascript 基本 | 更新日期: 2023-09-27 18:18:48
我有以下JavaScript代码:
<script type='text/javascipt' language="javascript">
function getUserLoc() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(displayResult, displayError);
}
else {
setMessage("Geolocation is not supported by this browser");
}
}
function displayResult(position) {
setMessage("Latitude: " + position.coords.latitude + ", Longitude: " + position.coords.longitude);
}
function setMessage(msg) {
document.forms[0].myLoc.value = msg;
}
function displayError(error) {
var errors = { 1: 'Permission denied', 2: 'Position unavailable', 3: 'Request timeout' };
setMessage("Error occured: " + errors[error.code]);
}
</script>
在ASP中也是如此。净:
<asp:Button ID="LoginButton" runat="server" Text="Log In" ValidationGroup="LoginUserValidationGroup"
OnClientClick="getUserLoc( )" />
然而,当我点击'LoginButton'我得到JavaScript错误:getuserlock is undefined
你的代码中有一个错别字。你有:
<script type='text/javascipt' language="javascript">
但应该是
<script type='text/javascript'>
(text/javascript)另外,删除方法调用中不必要的空格,因为它会给人一种输入参数的印象。(这不是必需的,但更多的是个人偏好)
OnClientClick="getUserLoc();"