jQuery从文本区域删除MS单词格式 [英] Jquery Remove MS word format from text area

查看:58
本文介绍了jQuery从文本区域删除MS单词格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的文本区域中删除MSWord格式信息,但不知道如何执行此操作. 这种情况就像我需要将粘贴的某些内容从MSWord复制到文本框编辑器中一样. 它被很好地复制了,但是问题是所有格式也都被复制了,所以我的300个字符的句子扩展为20000个字符的格式化句子. 有人可以建议我该怎么做吗?

I am trying to remove MSWord formatting information from my text area but not getting idea how to do this. The situation is like I need to copy paste some content from MSWord into a textbox editor. It gets copied well but the issue is that all the formatting also gets copied and so my 300 character sentence expands to 20000 character formatted sentence. Can any one suggest me what to do?

好了,我已经完成了一些研发工作.

Ok with some R&D done I have reached a certain stage.

这是我从Word文档复制的文本

Here's the text that I copied from Word document

Once the user clicks on the Cancel icon for a transaction on the Status of Business, and the transaction is eligible for cancellation, a new screen titled "Cancel Transaction" will appear, with the following fields: 

这是我在$(#textAreaId").val()中得到的内容

here's what I get in $("#textAreaId").val()

"

  Normal
  0




  false
  false
  false

  EN-US
  X-NONE
  X-NONE




























Once the user clicks on the Cancel icon for a
transaction on the Status of Business, and the transaction is eligible for
cancellation, a new screen titled "Cancel Transaction" will appear, with the
following fields: 



 /* Style Definitions */
 table.MsoNormalTable
    {mso-style-name:"Table Normal";
    mso-style-parent:"";
    line-height:115%;
    font-:11.0pt;"Calibri","sans-serif";
    mso-bidi-"Times New Roman";}

"

推荐答案

我终于找到了解决方案 在这里

I finally found the solution here is it

// removes MS Office generated guff
function cleanHTML(input) {
  // 1. remove line breaks / Mso classes
  var stringStripper = /(\n|\r| class=(")?Mso[a-zA-Z]+(")?)/g; 
  var output = input.replace(stringStripper, ' ');
  // 2. strip Word generated HTML comments
  var commentSripper = new RegExp('<!--(.*?)-->','g');
  var output = output.replace(commentSripper, '');
  var tagStripper = new RegExp('<(/)*(meta|link|span|\\?xml:|st1:|o:|font)(.*?)>','gi');
  // 3. remove tags leave content if any
  output = output.replace(tagStripper, '');
  // 4. Remove everything in between and including tags '<style(.)style(.)>'
  var badTags = ['style', 'script','applet','embed','noframes','noscript'];

  for (var i=0; i< badTags.length; i++) {
    tagStripper = new RegExp('<'+badTags[i]+'.*?'+badTags[i]+'(.*?)>', 'gi');
    output = output.replace(tagStripper, '');
  }
  // 5. remove attributes ' style="..."'
  var badAttributes = ['style', 'start'];
  for (var i=0; i< badAttributes.length; i++) {
    var attributeStripper = new RegExp(' ' + badAttributes[i] + '="(.*?)"','gi');
    output = output.replace(attributeStripper, '');
  }
  return output;
}

这篇关于jQuery从文本区域删除MS单词格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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