我有一个带有textarea的bootbox.dialog。我想将带有行制动器的textarea的值保存在与写入数据库相同的位置。所以我需要创建一个包含/n
或<br>
的字符串。
现在我的价值未定义。
这是我的代码:
$('#btnComment').click(function () {
var comment = $("#lblComment1").html();
popup.dialog({
title: translator.get('EditComment'),
message: "<textarea cols='60' rows='6' name='editComment'>" + comment + "</textarea>",
buttons: {
confirm: {
label: translator.get('EditComment'),
className: "btn-success",
callback: function (result) {
if (result === null) {
} else {
$("#editComment").val(result);
$("#lblComment1").html(result);
var ajaxData = {
Type: "Comment",
OrderId: $("#lblOrder").html(),
newValue: $("#editComment").val(),
MiddocID: $("#hidMiddocID").val()
}
$.ajax({
type: 'post',
url: configuration.baseUrl + '/api/OrdersPostback', //
dataType: "json",
data: JSON.stringify(ajaxData),
contentType: "application/json; charset=utf-8"
}).then(function (bResult) {
if (bResult) {
$("#editComment").val(result);
$("#lblComment1").html(result);
}
});
//$("#hidBtnComment").click();
}
}
},
cancel: {
label: translator.get('Cancel'),
className: "btn-default"
}
},
})
});
关于我能做什么的任何建议?
答案 0 :(得分:2)
将您的<textarea>
更改为:
message: "<textarea id='editComment' cols='60' rows='6' name='editComment'>" + comment + "</textarea>",
请注意,我已经添加了您在第一时间没做过的id="editComment"
。现在该元素可以通过$('#editComment')
获取,您可以使用.val()
和其他jQuery方法/插件。
答案 1 :(得分:0)
var dialog = bootbox.prompt({
title: "This is a prompt with a textarea!",
inputType: 'textarea',
callback: function (result) {
if (result ) {
console.log (dialog.find('textarea.bootbox-input-textarea').val());
}
}
});
你可以通过textarea类“bootbox-input-textarea”获取值 http://bootboxjs.com/documentation.html#prompt-option-input-type