Load HTML Page In Textarea

前提是你 提交于 2020-01-15 09:14:47

问题


I've been trying to load a html document into a textarea when the page loads.

I know you can use the ajax load api in JQuery...

$("#siteloader").load('startup.html');

but if I try to load this into the textarea...

var mirror = $("#pageloader"),
    input = $("#pagecode");

input.val(mirror.load('startup.html'));

I get [object Object] which I figured wouldn't work, but thought I'd try it anyway as I just didn't know if it would work or not.

Any help on how to do this would be greatly appreciated.


回答1:


try this

$(function () {
    function download_to_textbox(url, el) {
        $.get(url, null, function (data) {
            el.val(data);
        }, "text");
    }
    download_to_textbox("startup.html", $("#textareaID"));
});



回答2:


I would suggest you to try this one:

input.val(mirror.load('startup.html').html());


来源:https://stackoverflow.com/questions/18546295/load-html-page-in-textarea

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!