我是新手 - 我正在尝试在为用户加载变量时使用变量自动填充模态字段值。我有一种预感,我需要在加载时将.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');
});
});
答案 0 :(得分:0)
$('#reply_clicky').button().click(function(e){
$('#reply_form').dialog({
open: function(e, ui) {
$('#recipient').val(sender);
})
});
$('#reply_form').dialog('open');
});