我在ui上有以下html元素
<button onclick="getLocation()">Try It</button>
<p id="long"></p>Longitude<br>
<p id="lat"></p> Latitude<br>
<input type="text" id="ethaddress" placeholder="Enter your ETH address">
<button onclick="writeData()">Submit</button>
当有人访问该网站时,我只想向用户显示“尝试我”按钮。一旦他单击“尝试我”按钮,我希望此按钮消失,并且我想显示ID为long,lat和ethaddress的元素以及Submit按钮
您可以在此处找到示例的链接:http : //shiny-reaction.surge.sh
编辑现在您的问题是,在您的js文件中,您的getLocation()
函数定义为:
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
// x.innerHTML = "Geolocation is not supported by this browser.";
}
}
这样就不会隐藏或显示任何内容,您需要对此进行更新。
在香草js中,您可以尝试以下操作:
function getLocation(btn){
btn.style.display = "none";
document.getElementById("form").style.display = "block";
}
#form{
display: none;
}
<button id="button" onclick="getLocation(this)">Try It</button>
<form id="form">
<p id="long"></p>Longitude<br>
<p id="lat"></p> Latitude<br>
<input type="text" id="ethaddress" placeholder="Enter your ETH address">
<button onclick="writeData()">Submit</button>
</form>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句