javascript - 如何在 PageLoad 上获取 HiddenField 值(后面的代码)
问题描述
我使用 Java 脚本在隐藏字段上设置值,我想在中继器上为数据源使用隐藏字段值,但我有空值,因为我需要首先运行 Java 脚本并在页面加载时获取值。怎么可能?我的 Javascript 代码是:
<script type="text/javascript">
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function showPosition(position) {
//x.innerHTML = "Latitude: " + position.coords.latitude +
//"<br>Longitude: " + position.coords.longitude;
//console.log("Latitude: " + position.coords.latitude +
//"<br>Longitude: " + position.coords.longitude);
var lat = position.coords.latitude;
document.getElementById('<%= hdfLat.ClientID %>').value = lat;
var lon = position.coords.longitude;
document.getElementById('<%= hdfLong.ClientID %>').value = lon;
});
} else {
var error = "Geolocation is not supported by this browser.";
alert(error);
}
}
</script>
解决方案
看起来您可以调用您的函数或使其成为自执行函数。
获取位置();
推荐阅读
- javascript - Node.js 出现错误 Nginx 499(客户端关闭连接)
- javascript - React Router Dom v4 处理浏览器后退按钮
- c++ - 如何在类成员函数内的 printf 中获得编译警告
- json - 使用 Apache Spark 将表序列化为嵌套 JSON
- php - Symfony:未知的“humanize_bytes”过滤器
- android - 如何在 Android Firebase 中运行事务
- javascript - 无法调用类型缺少调用签名 TypeScript 错误的表达式
- c# - 如何按照 MVVM 模式绑定整个数据网格以查看 MVVM
- c++ - free() : MPI_Finalize() 期间的无效指针
- wireshark - 如何删除wireshark中的零数据包(空流)记录