复制带有格式的文本 [英] Copy Text With Formatting

查看:86
本文介绍了复制带有格式的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个Web应用程序,我想将按钮单击时的列表框中的数据复制到剪贴板.我有javascript来复制控件内的文本,但我想保留列表框的格式,即列表框中的每个句子都从新行开始.下面的代码是我在源代码中用于从列表框中复制项目的javascript.

Hi , I have a web app and i want to copy data from the listbox on button click to the clipboard. I have the javascript to copy the text within the control but i want to keep the formatting from the listbox i.e Each sentence within the listbox starts on a new line. The code below is the javascript that i am using in the source to copy items from the listbox.

<script type="text/javascript">
         function CopyToClipboard()
        {
          var theList = document.getElementById("ReasonListBox");
          var sContent = "";
          for(var i=0; i< theList.options.length ; i++)

           {

            sContent += theList.options[i].text + "\n";

           }

          window.clipboardData.setData("Text", sContent);

         }

         </script>




在此先感谢




thanks in advance

推荐答案

我在本地环境中测试了您的程序,

我在换行符上得到了列表项.

但是,我认为您是将复制的数据粘贴到
记事本,无法识别带有" \ n "字符的换行符,它仅显示矩形框(未知字符).

如果您要粘贴在其他环境中,那么我想您会得到的.

如果有帮助,请 投票 接受答案 .
I tested your program in Local environment,

And I got the listitems on newline itself.

But, I think you are pasting copied data to
notepad and it can not Recognize newline with ''\n'' char, It just displays rectangular box instead(unknown char).

If you will paste in other environment then I think you will get it.

Please vote and Accept Answer if it Helped.


这篇关于复制带有格式的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆