我有这个按钮,当点击时打开Outlook,显示我提供的详细信息。我还有一个TEXTAREA,它持有某些文本。我正在寻找一种方法让这个文字出现在我的外观体中。可以这样做吗?请在下面找到代码 -
<!DOCTYPE html>
<html lang="en">
<head>
<body>
<title>NMUK</title>
<script type=”text/javascript” language=”javascript” src=”Mail.js”></script>
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('.btnSendEmail').click(function (event) {
var email = 'example@email.com';
var subject = 'Creation Checklist';
var emailBody = $('#holdtext').val();
window.location = 'mailto:' + email + '?subject=' + subject + '&body=' + emailBody;
});
});
</script>
</head>
</head>
<br><br><br><br><br><br>
<div id="container">
<TEXTAREA ID="holdtext" rows="15" cols="100">
</TEXTAREA><br><br>
<button class="btnSendEmail" ><span>Send Email</span></button>
</div>
<div>
<style>#container {width:100%; text-align:center;}</style>
<h2></h2><br><br><br>
<p> <SPAN ID="Fetch"> Fetch next</p> <br>
<button class="button2" button onclick="FetchFunction()"><span>Next </span></button>
<p> <SPAN ID="GroupCompanies"> In AD goto Group</p>
<button class="button1" button onclick="GroupCompaniesFunction()"><span>Next </span></button>
<script>
function FetchFunction() {
holdtext.innerText = Fetch.innerText;
}
function GroupCompaniesFunction() {
holdtext.innerText += "\n"+GroupCompanies.innerText;
}
</script>
</body>
</html>
答案 0 :(得分:1)
尝试更改此行:
var emailBody = 'Body';
要:
var emailBody = $('#holdtext').val();
因为textarea
是表单元素。val()
是检索其中文本的正确方法。
请告诉我这是否有帮助!
<强>更新强>
要保留换行符,请更改此行:
window.location = 'mailto:' + email + '?subject=' + subject + '&body=' + emailBody;
要:
window.location = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);
答案 1 :(得分:0)
以下是我使用textarea标记和javascript的示例:
<div class="contact-form">
<br>
<div class="alert alert-success hidden" id="contactSuccess">
<strong>Success!</strong> Your message has been sent to us.
</div>
<div class="alert alert-error hidden" id="contactError">
<strong>Error!</strong> There was an error sending your message.
</div>
<form name="sentMessage" id="contactForm" novalidate>
<div class="form-group">
<input type="text" class="form-control" placeholder="Full Name" id="RecipientName"
required name="RecipientName"
data-validation-required-message="Please enter your name" />
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email"
id="RecipientEmail" name="RecipientEmail" required
data-validation-required-message="Please enter your email" />
</div>
<div class="form-group">
<textarea rows="10" cols="100" class="form-control"
placeholder="Please enter your message" id="RecipientMessage" name="RecipientMessage"
required data-validation-required-message="Please enter your message" minlength="5"
data-validation-minlength-message="Min 5 characters" maxlength="999"
style="resize:none">
</textarea>
</div>
<input class="btn btn-primary pull-right" type="submit" id="EmailSendButton"
name="EmailSendButton" value="send message" onclick="EmailData()">
</form><br /><br />
<div id="EmailConfirmation"></div>
</div>
<script>
function EmailData() {
$("#EmailSendButton").attr("disabled", "true");
var url = "/Home/EmailData";
var recipientName = $("#RecipientName").val();
var recipientEmail = $("#RecipientEmail").val();
var recipientMessage = $("#RecipientMessage").val();
var postData = { 'Name': recipientName, 'Email': recipientEmail, 'Message': recipientMessage }
$.post(url, postData, function (result) {
$("#EmailConfirmation").css({ 'display': 'block' });
$("#EmailConfirmation").text(result);
$("#EmailConfirmation").attr({ class: 'alert alert-success' })
$("#RecipientName").val('Your Name *');
$("#RecipientEmail").val('Your E-mail *');
$("#RecipientMessage").val('Your Message *');
})
}</script>