JavaScript id= 到 name= 表格
JavaScript id= to name= in a form
A 有一个处理本地化的 JavaScript。
这给了我
Position: <input type="text" id="Position1" name="Position1" value="">
这有效,我得到了网页上的当前位置。
现在,我想在表单中拥有该位置,并通过 php 脚本将其提供给我的 SQL。 php 有效。
我试过了:
<input type="hidden" name="poss" id="Position1">
我知道这行不通。
但是我该怎么做呢?如何从 id= 转换为 name= ??
脚本:
<script>
window.onload = function(){
var x = document.getElementById('Position1');
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.value = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.value = "" + position.coords.latitude + "," + position.coords.longitude;
}
getLocation();
};
</script>
Position: <input type="text" id="Position1" name="Position1" value="">
<input type="hidden" name="poss" id="Position1">
<input type="submit" style="height:40px;width:350px" />
</form>
试试 document.getElementsByName('poss')[0].value = "" + position.coords.latitude + "," + position.coords.longitude;
它应该可以工作
A 有一个处理本地化的 JavaScript。 这给了我
Position: <input type="text" id="Position1" name="Position1" value="">
这有效,我得到了网页上的当前位置。
现在,我想在表单中拥有该位置,并通过 php 脚本将其提供给我的 SQL。 php 有效。
我试过了:
<input type="hidden" name="poss" id="Position1">
我知道这行不通。 但是我该怎么做呢?如何从 id= 转换为 name= ??
脚本:
<script>
window.onload = function(){
var x = document.getElementById('Position1');
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.value = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.value = "" + position.coords.latitude + "," + position.coords.longitude;
}
getLocation();
};
</script>
Position: <input type="text" id="Position1" name="Position1" value="">
<input type="hidden" name="poss" id="Position1">
<input type="submit" style="height:40px;width:350px" />
</form>
试试 document.getElementsByName('poss')[0].value = "" + position.coords.latitude + "," + position.coords.longitude;
它应该可以工作