ExtJs4學習(十三)如何給檔案上傳按鈕加背景圖片

來源:互聯網
上載者:User

標籤:extjs4   上傳   按鈕   背景圖片   

我們日常看到的上傳按鈕都是這樣的


當然browse是預設的,我們可以去改變它,比如替換成“上傳”,配置為buttonText: ‘上傳‘,

如果我們想給按鈕添加背景圖片呢,你可能注意到了這個配置 buttonConfig

{  xtype: 'filefield',  emptyText: 'Select an image',  fieldLabel: 'Photo',  name: 'photo-path',  buttonText: '',  buttonConfig: {     iconCls: 'upload-icon'  }}

實際效果又是怎樣的呢



如果你的背景圖片剛好是那個大小,恭喜你後面的內容不用看了,你已經解決問題了。


只是如果你的背景圖片是這樣的大小呢


不妨試試,最後會發現,按鈕最終的顯式效果,竟然還是顯式那麼一點點,效果是這樣的


好像還是沒達到要求,不禁反問,這個寬度可以設定嗎?

我們試一下,代碼如下

{  xtype: 'filefield',  emptyText: 'Select an image',  fieldLabel: 'Photo',  name: 'photo-path',  buttonText: '',  buttonConfig: {    iconCls: 'browse',    width:154  }}
效果是這樣的


哎呀,好像還是不行,背景圖片好像被限制了,那能怎麼解決呢

這時候我想到了另外一個配置cls

{  xtype: 'filefield',  emptyText: 'Select an image',  fieldLabel: 'Photo',  name: 'photo-path',  buttonText: '',  buttonConfig: {    width:154,    height:41,    cls: 'browse',  }}
效果如下

這裡說到一點,filefield的width配置必須達到一定大小,不然按鈕會往左靠,覆蓋掉框,效果如下


現在達到我們的要求了,如果我們只需要按鈕,可以這樣

加兩個配置

buttonOnly: true,
hideLabel: true,

效果如下




ExtJs4學習(十三)如何給檔案上傳按鈕加背景圖片

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.