解決Extjs上傳圖片無法預覽的解決方法
更新時間:2012年03月22日 11:38:29 作者:
網(wǎng)上找了好多EXTJS上傳圖片預覽的,但都不行,,,下面雖然IE8可以但肯定還存在其它瀏覽器的兼容性問題,待擱應付一下吧
復制代碼 代碼如下:
{
width: 450,
fileUpload: true,
fieldLabel: '選擇圖片',
items: [{
xtype: 'textfield',
id: 'up_forth',
name: 'up_forth',
inputType: 'file',
width: 300
}]
}
預覽box
復制代碼 代碼如下:
{
columnWidth: .18,
bodyStyle: ' margin:4px 10px 10px 5px',
layout: 'form',
items: [{
xtype: 'box',
autoEl: {
width: 150, height: 150,
tag: 'div',
id: 'browser_up_forth'
}
}]
}
myfrom表示上傳控件外圍的FormPanel,, contril_id表示上傳控件的ID,只要在程序上預覽注冊該方法就可以,preview (myfrom,'up_forth' );
復制代碼 代碼如下:
var preview = function (myform, control_id) {
var img_reg = /\.([jJ][pP][gG]){1}$|\.([jJ][pP][eE][gG]){1}$|\.([gG][iI][fF]){1}$|\.([pP][nN][gG]){1}$|\.([bB][mM][pP]){1}$/
myform.on('render', function (f) {
myform.form.findField(control_id).on('render', function () {
Ext.get(control_id).on('change', function (field, newValue, oldValue) {
var obj = Ext.get(control_id).dom;
var url = getFullPath(obj);
if (img_reg.test(url)) {
var newPreview = Ext.get('browser_' + control_id).dom;
var showPic = Ext.get("showPic_" + control_id);
if (showPic != null) {
showPic.remove();//刪除原來的圖片
}
var imgDiv = document.createElement("div");
imgDiv.id = "showPic_" + control_id;
document.body.appendChild(imgDiv);
imgDiv.style.width = "150px";
imgDiv.style.height = "150px";
imgDiv.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod = scale)";
imgDiv.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = url;
newPreview.appendChild(imgDiv);
}
}, this);
}, this);
}, this);
}
//得到圖片地址
function getFullPath(obj) {
if (obj) {
// ie
if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
obj.select();
return document.selection.createRange().text;
}
// firefox
else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
if (obj.files) {
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
return obj.value;
}
}
相關文章
Extjs grid添加一個圖片狀態(tài)或者按鈕的方法
extjs的grid中我們經(jīng)常需要添加一個圖片狀態(tài)或者按鈕,下面將自己用過的一些方法與大家分享下2014-04-04Extjs 繼承Ext.data.Store不起作用原因分析及解決
有關Extjs 繼承Ext.data.Store 不起作用的原因有很多種,接下來與大家分享下,本人遇到的,這個Store寫出來之后 是不會起到作用的,感興趣的朋友可以看下詳細的原因及解決方法2013-04-04extjs tabpanel限制選項卡數(shù)量實現(xiàn)思路及代碼
使用的是用變量存儲 id 加載新的選卡時 交換 id ,從而限制了打開的選項卡數(shù)量,如果不是一定要這個效果,建議不要頻繁的關閉和創(chuàng)建tabpanel,感興趣的朋友可以參考下哈2013-04-04Ext修改GridPanel數(shù)據(jù)和字體顏色、css屬性等
這篇文章主要介紹了Ext修改GridPanel數(shù)據(jù)和字體顏色、css屬性等,需要的朋友可以參考下2014-06-06