Javascript 如何使用<;输入>;

Javascript 如何使用<;输入>;,javascript,php,html,ajax,laravel,Javascript,Php,Html,Ajax,Laravel,Html代码 <html> <body> <p>Click the button to get your coordinates.</p> <button onclick="getLocation()">Try It</button> <p id="demo"></p> <script> var x = document.getElementById("demo"); fun

Html代码

<html>

<body>

<p>Click the button to get your coordinates.</p>

<button onclick="getLocation()">Try It</button>

<p id="demo"></p>

<script>

var x = document.getElementById("demo");

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else { 
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}

function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude + 
    "<br>Longitude: " + position.coords.longitude;

}
</script>
<input  name="x.innerHTML" id="x.innerHTML" required value="">
</body>
</html>


单击按钮获取您的坐标

试试看

var x=document.getElementById(“演示”); 函数getLocation(){ if(导航器.地理位置){ navigator.geolocation.getCurrentPosition(showPosition); }否则{ x、 innerHTML=“此浏览器不支持地理位置。”; } } 功能显示位置(位置){ x、 innerHTML=“纬度:”+position.coords.Latitude+ “
经度:”+position.coords.Longitude; }
纬度:31.55460609994经度:74.3571581 我必须在提交时使用输入法将这些值存储在数据库中。


<html>

<body>

<p>Click the button to get your coordinates.</p>

<button onclick="getLocation()">Try It</button>

<p id="demo"></p>
<form action="insert_in_db.php">
    <input name="geoData" id="inputId" required value="">
    <input type="submit" value="Submit">
</form>

<script>

var x = document.getElementById("inputId");

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else { 
        x.value = "Geolocation is not supported by this browser.";
    }
}

function showPosition(position) {
    x.value = "Latitude: " + position.coords.latitude + 
    "<br>Longitude: " + position.coords.longitude;

}
</script>

</body>
</html>
单击按钮获取您的坐标

试试看

var x=document.getElementById(“inputId”); 函数getLocation(){ if(导航器.地理位置){ navigator.geolocation.getCurrentPosition(showPosition); }否则{ x、 value=“此浏览器不支持地理位置。”; } } 功能显示位置(位置){ x、 value=“Latitude:”+position.coords.Latitude+ “
经度:”+position.coords.Longitude; }
您需要一个
和服务器端代码来接受数据提交。。。顺便说一句输入上的
name=“x.innerHTML”id=“x.innerHTML”
希望实现什么?如果x.innerHTML存储经度和纬度值,并且我们在输入字段中存储为“提交”按钮上的隐藏和相同值存储>,是否有可能?没有提交按钮