【发布时间】:2019-10-29 22:21:27
【问题描述】:
我尝试了How do I add HTML form data to a mailto link 的解决方案,但该解决方案在我的移动设备上的 HTML5 sn-p 中不起作用。
<!-- contact -->
<section id="section-contact" class="section appear clearfix">
<div class="container">
<div class="row mar-bot40">
<div class="col-md-offset-3 col-md-6">
<div class="section-header">
<h2 class="section-heading animated" data-animation="bounceInUp">Contact us</h2>
<p>Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet consectetur, adipisci velit, sed quia non numquam.</p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div id="sendmessage">Your message has been sent. Thank you!</div>
<div id="errormessage"></div>
<form role="form" class="contactForm">
<div class="form-group">
<input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="tel" class="form-control" name="telephone" id="telephone" placeholder="111-111-1111" data-rule="email" data-msg="Please enter a valid telephone number" pattern="[0-9]{3}[0-9]{3}[0-9]{4}" required />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" />
<div class="validation"></div>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
<div class="validation"></div>
</div>
<div class="text-center">
<button type="submit" class="line-btn green" onclick="submitForm();return false;">Submit</button>
</div>
</form>
<script>
function submitForm(){
var name = document.getElementsByName("name")[0].value;
var email = document.getElementsByName("email")[0].value;
var phone = document.getElementsByName("telephone")[0].value;
var subject = document.getElementsByName("subject")[0].value;
var message = document.getElementsByName("message")[0].value;
window.open("mailto:denver.prophit@gmail.com?subject=" + encodeURIComponent(subject) +
"&body=Name:%20" + encodeURIComponent(name) +
"%0a%0aTelephone:%20" + encodeURIComponent(phone) +
"%0a%0a" + encodeURIComponent(message));
}
</script>
</div>
</div>
</div>
</section>
我所期望的是打开 gmail 应用程序。我得到的是滚动回到页面顶部。不确定在阅读了上一个问题中的问题后我错过了什么?
【问题讨论】:
-
phone\ n\ n + message可能是这个 -
和上面@Federico 强调的无效代码一样,
\n也不起作用,你应该改用%0a -
@DenverProphitJr.我的意思是你有一个语法错误。即使那些
\n确实有效,您也需要将它们放在一个字符串中,并且您在phone之后也缺少+。 -
@Federico 强调您的代码无效。你有
" + phone\ n\ n + message);。你的意思可能是" + phone + "\n\n" + message); -
您检查过浏览器控制台上的错误吗?