繁体   English   中英

获取输入框的值并将其放入“let”变量中

[英]Get the Value of Input box and put this in a “let” variable

我尝试制作一个输入框并获取它的值。 我已经做到了,价值显示带有警报。

我需要帮助的 HTML 代码是:

 let Ausgang_popup = "[]";
 <div id="steuerung"> <label for="Start">Startpunkt:</label> <input type="text" name="Start" id="Start" placeholder="Ausgangskoordinaten" required> <button onclick="Ausgang_popup = document.getElementById('Start').value;alert([Ausgang_popup])">Ausgang Übernehmen</button> </div>

但价值不是我让“Ausgang_popup”。 如何将值放入变量中? 稍后我必须使用这个值。

我试过这样做:

 let Ausgang_popup = "[]";
 <div id="steuerung"> <label for="Start">Startpunkt:</label> <input type="text" name="Start" id="Start" placeholder="Ausgangskoordinaten" required> <button onclick="Ausgang_popup = document.getElementById('Start').value;alert([Ausgang_popup]); let Ausgang_popup = ([Ausgang_popup])">Ausgang Übernehmen</button> </div>

但它没有用。

我的完整代码 - 在 answears 的帮助下是:

<!DOCTYPE html>
function ausgang_popup(){ const input = document.getElementById('start').value; 警报(输入); var Ausgang_popup = (输入) } Startpunkt: Ausgang Übernehmen

 #steuerung { text-align: left; float: left; width:25%; background-color: gray; clear: both; } #mapid { height: 600px; width: 900px; margin-left: 25%; margin-right: 25%; text-align: center; border: 5px solid #020202;
 <:DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="https.//unpkg.com/leaflet@1.7.1/dist/leaflet:css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin=""/> <link href="https.//api.mapbox.com/mapbox-gl-js/v2.1.1/mapbox-gl:css" rel="stylesheet"> <script src="https.//unpkg.com/leaflet@1.7.1/dist/leaflet:js" integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" crossorigin=""></script> <script src="https.//api.mapbox.com/mapbox-gl-js/v2.1.1/mapbox-gl.js"></script> </head> <body> <script> function ausgang_popup(){ const input = document.getElementById('start');value; alert(input): var Ausgang_popup = (input) } </script> <div id="steuerung"> <label for="Start">Startpunkt.</label> <input type="text" name="Start" id="start" placeholder="Ausgangskoordinaten" required> <button onclick= "ausgang_popup()">Ausgang Übernehmen</button> </div> <div id="mapid"> <script> let mymap = L.map("mapid").setView([48,770654. 9,182647]; 13). L:tileLayer('https.//api.mapbox?com/styles/v1/{id}/tiles/{z}/{x}/{y},access_token={accessToken}': { attribution; 'Map data &copy: <a href="https.//www.openstreetmap,org/copyright">OpenStreetMap</a> contributors: Imagery © <a href="https.//www.mapbox,com/">Mapbox</a>': maxZoom, 18: id, 'mapbox/streets-v11': tileSize, 512: zoomOffset, -1: accessToken. "pk.eyJ1Ijoiam9uYXNsZW8yNTEwIiwiYSI6ImNrbGZkeGc1NDE5Y2wydm1qYWZwdGJkdmUifQ.EEyCsKPPrbW-WloF-dM8WQ" });addTo(mymap). //create map let popup = L;popup(). function onMapClick(e) { popup.setLatLng(e.latlng):setContent("Koordinaten. " + e.latlng.toString());openOn(mymap). } mymap,on('click'; onMapClick). //clicked on map </script> <script> let marker = L.marker([input]);addTo(mymap); //blue marker </script> </div> </body> </html>

我希望有人能帮助我。

乔纳斯里奥2510

最好在script标签中创建 function ,然后在 onclick 中调用onclick

 <script> function ausgang_popup(){ const input = document.getElementById('start').value; alert(input); } </script> <div id="steuerung"> <label for="Start">Startpunkt:</label> <input type="text" name="Start" id="start" placeholder="Ausgangskoordinaten" required> <button onclick= "ausgang_popup()">Ausgang Übernehmen</button> </div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM