[英]Get value from textarea in bootbox
我有一个带有文本区域的 bootbox.dialog。 我想将带有 rowbrakes 的 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"
}
},
})
});
我能做什么有什么建议吗?
将您的<textarea>
更改为:
message: "<textarea id='editComment' cols='60' rows='6' name='editComment'>" + comment + "</textarea>",
请注意,我添加了您最初没有添加的id="editComment"
。 现在该元素将可以通过$('#editComment')
,您可以使用.val()
和其他 jQuery 方法/插件。
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());
}
}
});
您可以通过文本区域类“bootbox-input-textarea”获取值http://bootboxjs.com/documentation.html#prompt-option-input-type
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.