2016-06-21 39 views
1

我面临yui TextAreaCellEditor的问题。如何解码yui中的htmlentities TextAreaCellEditor

在yui语句下面,单击yui列打开带有保存和取消按钮的编辑器。

var myTextareaCellEditor = new YAHOO.widget.TextareaCellEditor(); 

var myColumnDefs = [ 
{key:"title",label:"Title", sortable:true ,editor: myTextareaCellEditor}, 
]; 

现在我的问题是当过我指定标题和数据库例如救我的标题是“text&data<new>”。 它正确得到保存,但是当我打开包含标题文本的编辑器。 它显示为“text&amp;data&lt;new&gt;”。 我想从编辑器中删除html实体。

任何帮助,非常感谢。

回答

2

TextareaCellEditor有一个名为“焦点”事件,当编辑器initailized和关注是它,焦点功能被调用时,你可以利用它。

var myTextareaCellEditor = new YAHOO.widget.TextareaCellEditor({ 
     focus:function(e){ 
      var textVal = myTextareaCellEditor.textarea.value; 
      textVal = decodeTEXT(textVal) ; 
      myTextareaCellEditor.textarea.value = textVal; 
     } 
}); 

myTextareaCellEditor.textarea.value:会给出现在文本区域的价值。这个值可以使用decodeText()函数解码并替换textarea的值。

function decodeTEXT(textVal){ 
    textVal = textVal.replace(/&amp;/g, '&'); 
    textVal = textVal.replace(/&gt;/g, '>'); 
    textVal = textVal.replace(/&lt;/g, '<'); 
    textVal = textVal.replace(/&quot;/g, '"'); 
    textVal = textVal.replace(/&#39;/g, "'"); 

    return textVal; 
} 

希望这会有所帮助。享受编码:)

+0

其作品Vivek,非常感谢。 –