简体   繁体   English

从 bootbox 中的 textarea 获取值

[英]Get value from textarea in bootbox

I have a bootbox.dialog with a textarea.我有一个带有文本区域的 bootbox.dialog。 I want to save the value of the textarea with rowbrakes in the same place as it was written to the database.我想将带有 rowbrakes 的 textarea 的值保存在写入数据库的同一位置。 So I need to create a string with /n or <br> .所以我需要用/n<br>创建一个字符串。

Right now is my value undefined.现在我的价值未定义。

Here is my code:这是我的代码:

$('#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"
            }
        },


    })

});

Any suggestions of what I can do?我能做什么有什么建议吗?

Change your <textarea> into this:将您的<textarea>更改为:

message: "<textarea id='editComment' cols='60' rows='6' name='editComment'>" + comment + "</textarea>",

Note that I've added the id="editComment" which you didn't do in the first place.请注意,我添加了您最初没有添加的id="editComment" Now that element will be fetchable by $('#editComment') and you can use .val() and other jQuery methods/plugins.现在该元素将可以通过$('#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());
        }
    }
});

you can get the value by textarea class "bootbox-input-textarea" http://bootboxjs.com/documentation.html#prompt-option-input-type您可以通过文本区域类“bootbox-input-textarea”获取值http://bootboxjs.com/documentation.html#prompt-option-input-type

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM