如何使 HTML 输入字段值预填充变量?在这种情况下,模态主体变量。 我阅读了有关使用 document.write 的信息,但我们如何将其与变量一起使用?
我们正在使用 Mandrill 和完整日历。
非常非常感谢!
代码:
{
title: 'Event',
start: '2016-03-26T11:00:00',
end: '2016-03-26T12:00:00',
},
],
eventClick: function(event) {
console.log(event)
// alert(event.start.format('MMMM Do YYYY'))
var start = event.start.format('MMMM Do YYYY'),
end = event.end.format('MMMM Do YYYY'),
html = '<p>Starts: ' + start + '<p>';
html += '<p>Ends: ' + end + '<p>';
var modal = $("#modal");
modal.find(".modal-title").html(event.title);
modal.find('.modal-body').html(html)
modal.modal();
}
});
});
});//]]>
</script>
<script type="text/javascript">
$(document).ready(function() {
// Generate a simple captcha
function randomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function generateCaptcha() {
$('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));
}
generateCaptcha();
$('#contactForm')
.formValidation({
})
.on('success.form.fv', function(e) {
// Prevent default form submission
e.preventDefault();
// Change these values to match with your application
var MANDRILL_API_KEY = 'YOUR-MANDRILL-API-KEY',
EMAIL_SUBJECT = 'Find Volunteerships - Sign Up Confirmation ',
var $form = $(e.target),
// Generate a message based on submitted form data
body = [
'<strong>Name:</strong> ' + $form.find('[name="firstName"]').val() + ' ' + $form.find('[name="lastName"]').val(),
'<strong>School</strong> ' + ($form.find('[name="school"]').val() || 'n/a'),
'',
'<strong>Message:</strong> ',
$form.find('[name="school"]').val()
].join('<br/>');
// Send the message
$.ajax({
type: 'POST',
url: 'http://mandrillapp.com/api/1.0/messages/send.json',
contentType: 'text/plain',
dataType: 'json',
data: {
key: MANDRILL_API_KEY,
message: {
from_name: $form.find('[name="fullName"]').val(),
from_email: $form.find('[name="email"]').val(),
to: [
{
email: $form.find('[name="email"]').val(),
name: $form.find('[name="fullName"]').val(),
'type': 'to'
}
],
auto_text: true,
subject: EMAIL_SUBJECT,
html: body
}
}
}).done(function(response) {
// Clear the form
$form.formValidation('resetForm', true);
// Regenerate the captcha
.on('err.form.fv', function(e) {
// Regenerate the captcha
generateCaptcha();
});
// Show the message
response.status === 'error'
? $('#alertContainer')
.removeClass('alert-success')
.addClass('alert-warning')
.html('Sorry, cannot register the sign up')
.show()
: $('#alertContainer')
.removeClass('alert-warning')
.addClass('alert-success')
.html('Your sign up has been successfully registered')
.show();
}).fail(function(jqXHR, textStatus, errorThrown) {
$('#alertContainer')
.removeClass('alert-success')
.addClass('alert-warning')
.html('Sorry, cannot register the sign up')
.show();
});
最佳答案
不确定你的意思,可能是这样的?
modal.find('.' + modal-body)
但是变量不能有带“-”符号的名字..
“modal-body
”等于“modal - body
”,所以它会减去一个。
关于javascript - 用变量预填充 HTML 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35905833/