【发布时间】:2016-09-02 14:14:37
【问题描述】:
需要你的帮助。
我不确定自己在做什么,而且我还将 jQuery 和 JS 混合在一起进行扩展,这根本没有任何意义,但我不知道该怎么做以及如何解决这个问题。
我希望form 中的#third-input 的value 在form 为submitted 时使用坐标进行更新。
<form class="flex-form" action="MAILTO:someone@example.com" method="post" enctype="text/plain">
<input id="first-input" type="text" placeholder="What is your name?" onfocus="this.placeholder = ''" onblur="this.placeholder = 'What is your name?'" value="" name="name">
<br />
<input id="second-input" type="text" pattern="[0-9]*" placeholder="Enter your phone number" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter your phone number'" value="" name="phone-number">
<br />
<input id="third-input" type="text" placeholder="Press button and Share location" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Press button and Share location'" value="" disabled="disabled" name="coordinates">
<br />
<input type="submit" value="Send Us Request">
</form>
这是我的这个表单的 jQuery
$('form').submit(function(){
var name = $('#first-input').val();
var telephone = $('#second-input').val();
var location = $('#third-input').val();
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
location.val() = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
location.val(position.coords.latitude + ", " + position.coords.longitude);
}
if(name === ''){
$('#first-input').css('border-top', 'solid 5px #ED6D60');
} else {
$('#first-input').css('border-top', 'solid 5px #0ED54D');
}
if(telephone === ''){
$('#second-input').css('border-top', 'solid 5px #ED6D60');
} else {
$('#second-input').css('border-top', 'solid 5px #0ED54D');
}
if(location === ''){
$('#third-input').css('border-top', 'solid 5px #ED6D60');
} else {
$('#third-input').css('border-top', 'solid 5px #0ED54D');
}
return false;
我从这个链接中获得的地理定位想法 [http://www.w3schools.com/][1]
如您所见,我对此很陌生,但我可以向您保证,我进行了一次健康的搜索,但没有找到任何解决方案。我也想避免使用插件。
谢谢。
欢迎使用 cmets 编写代码,我只是想确定“做什么”。
[1]:w3schools.com 上的地理位置
【问题讨论】:
标签: javascript jquery geolocation