开发者

jquery how can I move the code of a object to a textarea?

Im looking for a way to move a object (a banner) as a string to a textarea so that the user has it easy to copy past its content:

var object_sting = $('<div>').append($('#customized_banner'开发者_如何学JAVA).clone()).remove().html();
$('#customized_banner_code').attr("innerHTML", object_sting);

I'm trying to solve it with these two lines. The first results in a string and the second should add the string into the textarea. It unfortunately dosen't add it.

Strange is that both lines in itself do what they are expected to. the first does load the object in the variable as string. And the second does add text into the textarea if I replace the object_string with string.

Thanks for your hint! Markus


you can try:

$('#customized_banner_code').val(object_sting);

or even

$('#customized_banner_code').val(escape(object_sting));


You are adding the HTML code as code inside the textarea. Try to add it as text instead:

var object_sting = $('<div>').append($('#customized_banner').clone()).remove().html();
$('#customized_banner_code').val(object_sting);


Looks like you delete the whole thing before you get the string. Do this:

var div = $('<div>').append($('#customized_banner').clone());
var object_sting = div.html();
div.remove();
$('#customized_banner_code').val( object_sting );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜