extjshtmleditor的簡單介紹

本文目錄一覽:

關於Extjs 中htmlEditor的問題,怎麼動態的在htmleditor初始化時賦值,默認值就不要了

你好,Ext一般都是讀取json格式數據。htmlEditor屬於Ext form表單里的,所以我找到了以前做的一個關於form賦值的代碼例子給你貼出來,希望你能有所啟示。 代碼格式可能有點亂,不過你要相信一點,Ext處理數據一般都會用store。。。還有不懂的話隨時問e…..加油哈

註: 重點關注 下面items項內容

function editDept() {

var fp = new Ext.FormPanel({

frame : true,

border : 0,

items : [{

fieldLabel : ‘緊急程度’,

xtype : “combo”,

store : new Ext.data.JsonStore({

fields : [“id”, ‘text’, ‘value’],

idProperty : ‘id’,

data : [{ //這裡的數據可以通過Ext ajax與後後台聯繫,讀取後台數據

id : ‘c0’,

text : ‘清除’,

value : 0

}, {

id : ‘c1’,

text : ‘img src=”../images/dwbj.gif”‘,

value : 1

}, {

id : ‘c2’,

text : ‘img src=”../images/dwbj.gif”img src=”../images/dwbj.gif”‘,

value : 2

}]

}),

valueField : ‘id’,// 值,可選

displayField : ‘text’,// 顯示文本

mode : ‘local’,

forceSelection : true,// 必須選擇一項

triggerAction : ‘all’,// 因為這個下拉是只能選擇的,所以一定要設置屬性triggerAction為all,不然當你選擇了某個選項後,你的下拉將只會出現匹配選項值文本的選擇項,其它選擇項是不會再顯示了,這樣你就不能更改其它選項了。

editable : false,// 不允許輸入

selectOnFocus : true,

width : 200,

id : ‘wenshu’,

listeners : {

‘select’ : function(combo, srecord, indexss) {

var array = Ext.getCmp(‘mygrid’).getSelectionModel()

.getSelections();

var ids = “”;

for (var i = 0; i array.length; i++) {

ids += array[i].get(‘sginfo.sgid’) + “,”;

}

Ext.Ajax.request({

url : “sgJyInfo!updJjd.action”,

params : {

“jjd” : srecord.get(“value”),

“sgids” : ids

},

callback : function(options, success, response) {

var v = Ext.util.JSON.decode(response.responseText);

if (v.suc) {

for (var i = 0; i array.length; i++) {

array[i].set(‘jjd’, srecord.get(“value”));

};

_win.close();

} else {

Ext.Msg.alert(“提示”, v.msg);

}

}

});

}

}

}]

})

var _win = new Ext.Window({

title : “修改處理情況”,

height : 83,

modal : true,

width : 370,

// iconCls : _iconCls,

id : “edit_win”,

bodyStyle : ‘padding:5px 5px’,

items : [fp]

});

_win.show();

}

Extjs4.0如何限制的htmleditor的輸入長度,具體的方法

htmleditor 沒有相應的屬性限制長度。

只能是輸入完之後,提交的時候驗證一下。

這個不用給你寫了吧? 還是寫一下吧。。

var htmleditor = new Ext.form.field.HtmlEditor({…..});

if(htmleditor.getValue().length 100){

    Ext.Msg.alert(‘提示’, ‘不能超出100字符’);

    return;

}

extjs中HtmlEditor怎樣使用,

var descriptionHtmlEditor = new Ext.form.HtmlEditor({

id:’dhtml’,

name: ‘description’,

allowBlank:true,

width:590,

height:450

})

var fpmu=new Ext.form.FormPanel({

border:false,

width:350,

frame:true,

autoHeight:true,

layout:’form’,

border:false,

items:[descriptionHtmlEditor]

})

var win = new Ext.Window({

title : ‘窗口’,

closeAction : ‘hide’,

layout:’fit’,

width : 750,

height : 360,

resizable : false,

modal : true,

items:[fpmu],

buttons:[{text:’提交’,handler:function(){

fpmu.getForm().submit({

url:’test.aspx?cmd=htmleidtor’,

method:’post’,

waitMsg:’正在上傳文件中…’,

// params:{he:Ext.state.Manager.get(“cun”)},

success:function(descriptionHtmlEditor,o){

// Ext.Msg.alert(‘提示’,o.result.message);

if(o.result.message==’上傳成功’){

}

},

failure:function(descriptionHtmlEditor,o){

Ext.Msg.alert(‘信息’,’操作失敗!’+ o.result.error);

}

})

}}]

});

win.show();

測試通過,FIREBUG有POST值到後台。

extjs 3.4中 怎麼給htmlEdit添加圖片插件 實現圖片上傳功能

首先要使用extjs自帶的HTMLEditor,然後在原有的工具條上添加一個圖片按鈕,點擊這個圖片按鈕要彈出窗口,這個窗口負責實現上傳功能,實現上傳後,要將上傳的圖片路徑添加到 HTMLEditor 的光標處,並且要以IMG/IMG的方式,這樣 HTMLEditor 才能解析出來。實現代碼如下:

前台JSP頁面

fieldLabel : ‘商品特性’,

id : ‘shopSp.spTxms’,

name : ‘shopSp.spTxms’,

xtype : ‘StarHtmleditor’,

anchor : ‘93%’

這其中引用了StarHtmleditor,StarHtmleditor.js的代碼如下,直接將代碼複製下來,然後新建個JS,全複製進去就行了。

var HTMLEditor = Ext.extend(Ext.form.HtmlEditor, {

   addImage : function() {

       var editor = this;

       var imgform = new Ext.FormPanel({

           region : ‘center’,

           labelWidth : 55,

           frame : true,

           bodyStyle : ‘padding:5px 5px 0’,

           autoScroll : true,

           border : false,

           fileUpload : true,

           items : [{

                       xtype : ‘textfield’,

                       fieldLabel : ‘選擇文件’,

                       id : ‘UserFile’,

                       name : ‘UserFile’,

                       inputType : ‘file’,

                       allowBlank : false,

                       blankText : ‘文件不能為空’,

                       anchor : ‘90%’

                   }],

           buttons : [{

               text : ‘上傳’,

               handler : function() {

                   if (!imgform.form.isValid()) {return;}

                   imgform.form.submit({

                       waitMsg : ‘正在上傳……’,

                       url : ‘HTMLEditorAddImgCommonAction.action’,

                       success : function(form, action) {

                           var element = document.createElement(“img”);

element.src = action.result.fileURL;

                           if (Ext.isIE) {

                               editor.insertAtCursor(element.outerHTML);

                           } else {

                               var selection = editor.win.getSelection();

                               if (!selection.isCollapsed) {

                                   selection.deleteFromDocument();

                               }

                               selection.getRangeAt(0).insertNode(element);

                           }

                           //win.hide();//原始方法,但只能傳一個圖片

                           //更新後的方法

                           form.reset();

        win.close();

                       },

                       failure : function(form, action) {

                           form.reset();

                           if (action.failureType == Ext.form.Action.SERVER_INVALID)

                               Ext.MessageBox.alert(‘警告’,’上傳失敗’,action.result.errors.msg);

                       }

                   });

               }

           }, {

               text : ‘關閉’,

               handler : function() {

                   win.close(this);

               }

           }]

       })

       var win = new Ext.Window({

                   title : “上傳圖片”,

                   width : 300,

                   height : 200,

                   modal : true,

                   border : false,

                   iconCls : “picture.png”,

                   layout : “fit”,

                   items : imgform

               });

       win.show();

   },

   createToolbar : function(editor) {

       HTMLEditor.superclass.createToolbar.call(this, editor);

       this.tb.insertButton(16, {

                   cls : “x-btn-icon”,

                   icon : “picture.png”,

                   handler : this.addImage,

                   scope : this

               });

   }

});

Ext.reg(‘StarHtmleditor’, HTMLEditor);

JS的第一句 var HTMLEditor = Ext.extend(Ext.form.HtmlEditor, 網上是沒有var的,不用var不知道為什麼總是報錯,另外JS一定要與JSP的編碼方式一致,要不然報莫名其妙的錯誤,而且錯誤都沒有顯示。

後台java代碼

/****

* HTMLEditor增加上傳圖片功能:

* 1、上傳圖片後,需要將圖片的位置及圖片的名稱返回給前台HTMLEditor

* 2、前台HTMLEditor根據返回的值將圖片顯示出來

* 3、進行統一保存

* @param 上傳圖片功能

* @return JSON結果

* @throws IOException

*/

public void HTMLEditorAddImg() throws IOException {

if(!””.equals(UserFile) UserFile != null UserFile.length() 0){

File path = ImportImg(UserFile, “jpg”);

UserFilePath = “../” + path.toString().replaceAll(“\\\\”, “/”).substring(path.toString().replaceAll(“\\\\”, “/”).indexOf(“FileImg”));

}

this.getResponse().setContentType(“text/html”);

this.getResponse().getWriter().write(“{success:’true’,fileURL:'” + UserFilePath + “‘}”);

}

特別要注意的是路徑問題,路徑問題主要有2點需要注意:

1、前台頁面引用 StarHtmleditor.js 的路徑一定要正確;

2、 Htmleditor上傳的圖片路徑一定要改,因為上傳之後圖片路徑變為,在正常使用中圖片不顯示,要將該地址替換為服務器的IP地址;替換方法如下:

//獲取本地IP地址,因為extjs的htmleditor上傳的照片路徑有問題,需要將路徑替換為本機IP地址

InetAddress inet = InetAddress.getLocalHost();

shopSp.setSpTxms(shopSp.getSpTxms().replace(“localhost”, inet.getHostAddress().toString()));

這樣基本就完成了這個HTMLEditor上傳圖片功能。

如圖:

ExtJs htmleditor如何設置不顯示工具欄?

enableFont : Boolean

允許字體選項。Safari 中無效。(默認為 true)。Enable… 允許字體選項。Safari 中無效。(默認為 true)。Enable font selection. Not

available in Safari. (defaults to true) HtmlEditor

enableFontSize : Boolean

允許增大/縮小字號按鈕(默認為 true)。Enable the in… 允許增大/縮小字號按鈕(默認為 true)。Enable the increase/decrease font size

buttons (defaults to true) HtmlEditor

enableFormat : Boolean

允許粗體、斜體和下劃線按鈕(默認為 true)。Enable the … 允許粗體、斜體和下劃線按鈕(默認為 true)。Enable the bold, italic and underline

buttons (defaults to true) HtmlEditor

enableLinks : Boolean

允許創建鏈接按鈕。Safari 中無效。(默認為 true)。Enab… 允許創建鏈接按鈕。Safari 中無效。(默認為 true)。Enable the create link button.

Not available in Safari. (defaults to true) HtmlEditor

enableLists : Boolean

允許項目和列表符號按鈕。Safari 中無效。(默認為 true)。E… 允許項目和列表符號按鈕。Safari 中無效。(默認為 true)。Enable the bullet and numbered

list buttons. Not available in Safari. (defaults to true) HtmlEditor

enableSourceEdit :

Boolean

允許切換到源碼編輯按鈕。Safari 中無效。(默認為 true)。E… 允許切換到源碼編輯按鈕。Safari 中無效。(默認為 true)。Enable the switch to source

edit button. Not available in Safari. (defaults to true) HtmlEditor

fieldClass : String 表單元素一般狀態CSS樣式(默認為”x-form

快快把分給我…

原創文章,作者:XYDW,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/142981.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
XYDW的頭像XYDW
上一篇 2024-10-14 18:48
下一篇 2024-10-14 18:48

相關推薦

  • Python簡單數學計算

    本文將從多個方面介紹Python的簡單數學計算,包括基礎運算符、函數、庫以及實際應用場景。 一、基礎運算符 Python提供了基礎的算術運算符,包括加(+)、減(-)、乘(*)、除…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • Python海龜代碼簡單畫圖

    本文將介紹如何使用Python的海龜庫進行簡單畫圖,並提供相關示例代碼。 一、基礎用法 使用Python的海龜庫,我們可以控制一個小海龜在窗口中移動,並利用它的“畫筆”在窗口中繪製…

    編程 2025-04-29
  • Python櫻花樹代碼簡單

    本文將對Python櫻花樹代碼進行詳細的闡述和講解,幫助讀者更好地理解該代碼的實現方法。 一、簡介 櫻花樹是一種圖形效果,它的實現方法比較簡單。Python中可以通過turtle這…

    編程 2025-04-28
  • Python大神作品:讓編程變得更加簡單

    Python作為一種高級的解釋性編程語言,一直被廣泛地運用於各個領域,從Web開發、遊戲開發到人工智能,Python都扮演着重要的角色。Python的代碼簡潔明了,易於閱讀和維護,…

    編程 2025-04-28
  • 用Python實現簡單爬蟲程序

    在當今時代,互聯網上的信息量是爆炸式增長的,其中很多信息可以被利用。對於數據分析、數據挖掘或者其他一些需要大量數據的任務,我們可以使用爬蟲技術從各個網站獲取需要的信息。而Pytho…

    編程 2025-04-28
  • 如何製作一個簡單的換裝遊戲

    本文將從以下幾個方面,為大家介紹如何製作一個簡單的換裝遊戲: 1. 遊戲需求和界面設計 2. 使用HTML、CSS和JavaScript開發遊戲 3. 實現遊戲的基本功能:拖拽交互…

    編程 2025-04-27
  • Guava Limiter——限流器的簡單易用

    本文將從多個維度對Guava Limiter進行詳細闡述,介紹其定義、使用方法、工作原理和案例應用等方面,並給出完整的代碼示例,希望能夠幫助讀者更好地了解和使用該庫。 一、定義 G…

    編程 2025-04-27
  • 2的32次方-1:一個看似簡單卻又複雜的數字

    對於計算機領域的人來說,2的32次方-1(也就是十進制下的4294967295)這個數字並不陌生。它經常被用來表示IPv4地址或者無符號32位整數的最大值。但實際上,這個數字卻包含…

    編程 2025-04-27
  • 製作一個簡單的管理系統的成本及實現

    想要製作一個簡單的管理系統,需要進行技術選型、開發、測試等過程,那麼這個過程會花費多少錢呢?我們將從多個方面來闡述製作一個簡單的管理系統的成本及實現。 一、技術選型 當我們開始思考…

    編程 2025-04-27

發表回復

登錄後才能評論