Modify the button style of the uploaded file

Source: Internet
Author: User

CSS style:

. a-upload {
padding:0px 10px;
height:30px;
line-height:30px;
position:relative;
Cursor:pointer;
Color: #888;
Background: #fafafa;
border:1px solid #ddd;
border-radius:4px;
Overflow:hidden;
Display:inline-block;
*display:inline;
*zoom:1;
margin:10px;
}

. a-upload Input {
Position:absolute;
font-size:100px;
right:0;
top:0;
opacity:0;
Filter:alpha (opacity=0);
Cursor:pointer
}


HTML code:

<a href= "javascript:;" class= "A-upload" >
<input type= "File" name= "id=" "> Upload Avatar
</a>
<div class= "Showfilename" ></div>
<div class= "Fileerrortip" ></div>

jquery Code

function Getobjecturl (file) {
var url = null;
if (window.createobjecturl!=undefined) {//Basic
url = window.createobjecturl (file);
} else if (window. url!=undefined) {//Mozilla (Firefox)
url = window. Url.createobjecturl (file);
} else if (window.webkiturl!=undefined) {//WebKit or Chrome
url = window.webkitURL.createObjectURL (file);
}
return URL;
}


$ (". A-upload"). On ("Change", "input[type= ' file ']", function () {
var filepath=$ (this). Val ();
var arr=filepath.split (' \ \ ');
var filename=arr[arr.length-1];
$ (". Showfilename"). HTML (fileName);
$ ('. AppIcon '). attr (' src ', Getobjecturl ($ (this) [0].files[0]));
Console.log (Getobjecturl ($ (this) [0].files[0])

})

Modify the button style of the uploaded file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.