分享

Extjs portal 初探 - textarea 与 pre

 9loong 2009-11-11
 
很久没用过 ,textarea 了,一般就是用用  htmleditor 这种控件 ,而今次的动画编辑,要在web client 编辑资源文字,而资源文字要用在不能显示html的地方,如彩信 ,于是就用 textarea 了 ,另外要做一个 预览 各个帧的界面 ,结果遇到了不少问题。

 

 

 

 

 

 

 

 

1.textarea 编辑后 提交到服务器 ,服务器确认后再传回,里面的  < > 已被 extjs 自动编码为 < >

 

Js代码 复制代码
  1. frame_edit.form.submit({   
  2.                             url : 'setFrame.jsp',   
  3.                             success : function(form, action) {   
  4. //  textResourceText 输 < ,服务器传过来 <   //action.result.data.textResourceText变成 <        
  5.  //需要自己    Ext.util.Format.htmlDecode                                  
  6. action.result.data.textResourceText=Ext.util.Format.htmlDecode(   
  7. action.result.data.textResourceText);   
  8.                                    2.textarea 输入的内容 换行空格等要在 web 上 原样显示 ,有两个方法

 

 

    1. 运用 pre 标签 (老式的html标签,但是具有广泛的兼容性) ,将 textarea 输入的内容 放在 <pre> </pre> 中间  ,但这样的话 换行只有在 textarea 输入的内容 换行的时候才会换行 ,不会随屏幕宽度自动换行。

 

     2.css 指定 white-space:pre   如 <p style="white-space:pre;"></p>  ,但是ie6 及其以下版本不支持

 

     3.replace(/\n/g,'<br/>').replace(/\s/g,' ') 一方面 换行在 textarea 输入的内容 换行的时候会换行 ,另一方面 会随屏幕宽度自动换行。 但是若指定宽度,并且遇到了长英文字符,如  email:yiminghe@xxxxxxxxxxx.com 则横向滚动条又会出现了。解决方法:

             3.1 : 在 IE 和 Safari 1.3+ 下相对比较容易解决,使用 CSS 属性 word-wrap: break-word;。

             3.2 : 而 Firefox 和 Opera 浏览器 ,无法识别 word-wrap: break-word; 和 word-break:break-all; 属性。可以通过脚本给连续字符的每个字符之间插入 \ u8203 的字符(该字符在非 IE 浏览下不占据空间) ,使连续变为了不连续,达到了换行的效果。

Js代码 复制代码
  1. breakWord = function(dEl){   
  2.     var dWalker = document.createTreeWalker(dEl, NodeFilter.SHOW_TEXT, nullfalse);   
  3.     var node,s,c = String.fromCharCode('8203');   
  4.     while (dWalker.nextNode()){   
  5.         node = dWalker.currentNode;   
  6.         s = trim( node.nodeValue ) .split('').join(c);   
  7.         node.nodeValue = s;   
  8.     }   
  9.     return true;   
  10. }   

     上述3个方法  都要先将 < ,> ," ,& 转义 ,用 Ext.util.Format.htmlEncode 即可

综合来说 ,还是不如 htmleditor 方便 ,做web开发确实还是 能用 htmleditor就用 htmleditor,更好就用 fckeditor 了

 

 

附录 :http://www./360/dhtml/css-word-break.html

 

Js代码 复制代码
  1. function breakWord(dEl){   
  2.            
  3.            
  4.         if(!dEl || dEl.nodeType !== 1){   
  5.              
  6.           return false;   
  7.            
  8.         } else if(dEl.currentStyle && typeof dEl.currentStyle.wordBreak === 'string'){   
  9.              
  10.           //Lazy Function Definition Pattern, Peter's Blog   
  11.           //From http://peter./article/3556   
  12.              
  13.           breakWord = function(dEl){   
  14.             //For Internet Explorer   
  15.             dEl.runtimeStyle.wordBreak = 'break-all';   
  16.             return true;   
  17.           }   
  18.              
  19.           return breakWord(dEl);   
  20.             
  21.         }else if(document.createTreeWalker){   
  22.           
  23.           //Faster Trim in Javascript, Flagrant Badassery   
  24.           //http://blog./archives/faster-trim-javascript   
  25.              
  26.           var trim = function  (str) {   
  27.             str = str.replace(/^\s\s*/, '');   
  28.             var ws = /\s/,   
  29.             i = str.length;   
  30.             while (ws.test(str.charAt(--i)));   
  31.             return str.slice(0, i + 1);   
  32.           }   
  33.              
  34.           //Lazy Function Definition Pattern, Peter's Blog   
  35.           //From http://peter./article/3556   
  36.              
  37.           breakWord = function(dEl){   
  38.                
  39.             //For Opera, Safari, and Firefox   
  40.             var dWalker = document.createTreeWalker(dEl, NodeFilter.SHOW_TEXT, nullfalse);   
  41.             var node,s,c = String.fromCharCode('8203');   
  42.             while (dWalker.nextNode())   
  43.             {   
  44.               node = dWalker.currentNode;   
  45.               //we need to trim String otherwise Firefox will display    
  46.               //incorect text-indent with space characters   
  47.               s = trim( node.nodeValue ) .split('').join(c);   
  48.               node.nodeValue = s;   
  49.             }   
  50.             return true;   
  51.           }   
  52.              
  53.           return breakWord(dEl);   
  54.              
  55.              
  56.         }else{   
  57.           return false;   
  58.         }   
  59.       }  

 

  (#)

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约