0
我爲模態窗口使用Messi。在這種情況下,我添加了一個文本區域到模態窗口,但由於DOM已經加載,所以無法訪問它中的值。我當前的代碼如下:AJAX調用在DOM加載後在模態窗口中獲取textarea的內容
new Messi('<i class="fa fa-envelope fa-3x pull-left"></i><strong>Send a message to ' + co + '. </strong><br />Check the Messages tab to converse with ' + co + '.'
+ '<label class="textarea">'
+ '<textarea id="themessage" name="notes" placeholder="Enter Message" rows="5" style="margin-top:11px"></textarea>'
+ '</label>'
+ '<div class="note">Enter Message</div>', {
title: 'Message ' + co ,
titleClass: '',
modal: true,
closeButton: true,
unload:false,
buttons: [{
id: 0,
label: 'Send Message',
class: '',
val: 'Y'
}],
callback: function (val) {
if (val === 'Y') {
var themsg = $("textarea#themessage").val();
$.ajax({
type: 'post',
url: 'controller.php',
data: {
'processMessage': id,
'recipient':recipient,
'company': co,
'msgsubject':msgsubject,
'body': themsg,
'title':encodeURIComponent(name)
},
beforeSend: function() {
parent.animate({
'backgroundColor': '#FFF'
}, 400);
},
success: function (msg) {
$('html, body').animate({
scrollTop: 0
}, 600);
$('#msgholder').html(decodeURIComponent(msg));
}
});
}
}
});
在回調函數中,我試着抓住了價值,但沒有運氣
var themsg = $("textarea#themessage").val();
我也試過,包括在最初的點擊功能此功能時,變量調用模式窗口,但它不起作用,因爲在編輯模態文本區域之前加載了DOM。
$('body').on('click', 'a.mod-button', function() {
var themsg = $("textarea#themessage").val();
console.log(themsg);
});
當用戶在模態窗口中單擊提交時,如何獲取新輸入的文本?
謝謝我試過但結果相同... –