문제

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').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 );
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top