jquery 如何将对象的代码移动到文本区域?
我正在寻找一种将对象(横幅)作为字符串移动到文本区域的方法,以便用户可以轻松复制其内容:
var object_sting = $('<div>').append($('#customized_banner').clone()).remove().html();
$('#customized_banner_code').attr("innerHTML", object_sting);
我正在尝试用这两行来解决它。第一个结果是一个字符串,第二个应该将该字符串添加到文本区域中。不幸的是它没有添加它。
奇怪的是,两条线路本身都按照预期进行。第一个确实将对象作为字符串加载到变量中。如果我用字符串替换 object_string,第二个确实会将文本添加到文本区域中。
谢谢你的提示! 马库斯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以尝试:
或者甚至
you can try:
or even
您将 HTML 代码添加为文本区域内的代码。尝试将其添加为文本:
You are adding the HTML code as code inside the textarea. Try to add it as text instead:
看起来你在获取字符串之前删除了整个内容。这样做:
Looks like you delete the whole thing before you get the string. Do this: