Mar*_*ala 6 javascript jsf html5 el geolocation
我正在做JSF地理定位服务,我需要将经度和经度传递给bean进行处理.HTML5允许使用JavaScript获取位置,例如http://code.google.com/p/geo-location-javascript/中所做的操作.将以下代码放入JSF页面会显示带GPS坐标的警报
<script>
if (geo_position_js.init()) {
geo_position_js.getCurrentPosition(success_callback,error_callback,{enableHighAccuracy:true,options:5000});
} else {
alert("Functionality not available");
}
function success_callback(p) {
alert('lat='+p.coords.latitude.toFixed(2)+';lon='+p.coords.longitude.toFixed(2));
}
function error_callback(p) {
alert('error='+p.message);
}
</script>
Run Code Online (Sandbox Code Playgroud)
如何使用p.coords.latitude.toFixed(2)值将其传递给h:inputtext组件?
你需要意识到JSF在webserver上运行并产生一堆HTML/CSS/JS代码,这些代码从webserver发送到webbrowser,而webbrowser只运行HTML/CSS/JS.在webbrowser中右键单击该页面,然后选择" 查看源".代替<h:inputText>你,你会看到类似的东西
<input type="text" id="formid:inputid" />
Run Code Online (Sandbox Code Playgroud)
在JS中,您可以使用document函数轻松地从HTML DOM中获取HTML元素并进行更改.
var input = document.getElementById('formid:inputid');
input.value = 'new value';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25935 次 |
| 最近记录: |