1

如何将检索到的文本放入 Trumbowyg Textarea。我想使用 Trumbowyg 编辑保存的内容。我使用 Jquery Ajax 从数据库中获取了一些文本。我正在尝试使用 .html() 和 .text() 函数放置文本,但无法正常工作。我正在尝试从互联网上找到解决方案,直到现在还没有得到它。

HTML:

<textarea name="description" class="form-control" placeholder="Enter Description"></textarea>

查询:

$(".edit").click(function(){
        var id=$(this).attr("data-id");  
         $.ajax({
                type: "POST",
                url: "ajax.php",
                data: "formName=edit_sales_lead&id=" + id,
                success: function(res){
                    if(res!=""){
                            res=JSON.parse(res);
                            console.log(res[1]);  //test description
                            $("input[name='name']").val(res[0]);   
                            $("textarea[name='description']").html(res[1]);
                    }else{
                        console.log(res);
                    }
                }
            });
    });
4

1 回答 1

3
document.getElementById('editor').innerHTML = '<p>Your html content</p>';

或如@Taplar 在评论中建议的那样:

$('#editor').trumbowyg('html', "<p>Your content here</p>");

将是加载 html 内容的另一种方式。

于 2019-11-22T05:14:03.387 回答