我是一个新手 - 并且试图在为用户加载时使用变量自动填充模态字段值。我有一种预感,我需要在加载时将 .val() 添加到对话框中,但不确定。目前我正在尝试像标准表单一样加载值。感谢您对此提供的任何帮助-
用于激活模态的按钮:
<input type="button" id="reply_clicky" name="emailmessage" onClick="updateReplyName('{{email.sender}}')" value="Reply" >
形式:
<div id="reply_form" title="Send Message">
<form id="replyemailform" method="POST" action="/sendemailmessage" name="emailposting">
<p>
<label for="recipient">To:</label>
<input type="text" name="recipient" id="recipient">
</p>
<p>
<label for="subject">Subject: </label>
<input type="text" name="subject" id="subject">
</p>
<p>
<label for="content">Message: </label>
<textarea name="content" id ="content" class="textarea" rows="4" style=""></textarea>
</p>
</form>
</div>
Javascript:
$(document).ready(function(){
$('#reply_form').dialog({
autoOpen: false,
height: 375,
width: 350,
modal: true,
buttons: [
{
text: "Cancel",
click: function() {
$(this).dialog("close");
}},
{
text: "Submit",
click: function() {
$('#replyemailform').submit();
}}
]
});
$('#reply_clicky').button().click(function(e){
$('#reply_form').dialog('open');
});
});
function updateReplyName(sender){
console.log("updateReplyName function fired");
document.getElementById('recipient').value = sender;
}
编辑以包含 DevlshOne 的建议:
$(document).ready(function(){
$('#reply_form').dialog({
autoOpen: false,
height: 375,
width: 350,
modal: true,
buttons: [
{
text: "Cancel",
click: function() {
$(this).dialog("close");
}},
{
text: "Submit",
click: function() {
$('#replyemailform').submit();
}}
]
});
$('#reply_clicky').button().click(function(e){
$('#reply_form').dialog({
open: function(e, ui) {
$('#recipient').val('value is here');
}
});
$('#reply_form').dialog('open');
});
});