How to change the button text of <input type=“f

2018-12-31 18:51发布

<input type="file" value="Browse" name="avatar" id="id_avatar" />

I tried to modify the value, but it's not working. How to customize the button text?

标签: html input
15条回答
裙下三千臣
2楼-- · 2018-12-31 19:13
  1. Before that <input type="file">, add an image and <input style="position:absolute"> it will occupy the space of <input type="file">
  2. Use the following CSS to the file element

    position:relative;  
    opacity:0;  
    z-index:99;
    
查看更多
宁负流年不负卿
3楼-- · 2018-12-31 19:14

The "upload file..." text is pre-defined by the browser and can't be changed. The only way to get around this is to use a Flash- or Java-based upload component like swfupload.

查看更多
看淡一切
4楼-- · 2018-12-31 19:17

This is a JQuery plugin to change the button text of an input file element.

Example HTML:

<input type="file" id="choose-file" />

Example JS:

$('#choose-file').inputFileText({
    text: 'Select File'
});

Result:

plugin result

查看更多
孤独寂梦人
5楼-- · 2018-12-31 19:22

Use <label> for the caption

<form enctype='multipart/form-data' action='/uploads.php' method=post>
<label for=b1>
    <u>Your</u> caption here
<input style='width:0px' type=file name=upfile id=b1
 onchange='optionalExtraProcessing(b1.files[0])'
 accept='image/png'>
</label>
</form>

This works without any javascript. You can decorate the label to any degree of complexity, to your heart's content. When you click on the label, the click automatically gets redirected to the file input. The file input itself can be made invisible by any method. If you want the label to appear like a button, there are many solutions, e.g.:

label u {
    -webkit-appearance: button;
    -moz-appearance: button;
    appearance: button;

    text-decoration: none;
    color: initial;
}
查看更多
十年一品温如言
6楼-- · 2018-12-31 19:23

This is an alternative solution that may be of help to you. This hides the text that appears out of the button, mixing it with the background-color of the div. Then you can give the div a title you like.

<div style="padding:10px;font-weight:bolder; background-color:#446655;color: white;margin-top:10px;width:112px;overflow: hidden;">
     UPLOAD IMAGE <input style="width:100px;color:#446655;display: inline;" type="file"  />
</div>
查看更多
低头抚发
7楼-- · 2018-12-31 19:24

Hide the file input. Create a new input to capture a click event and forward it to the hidden input:

<input type="button" id="loadFileXml" value="loadXml" onclick="document.getElementById('file').click();" />
<input type="file" style="display:none;" id="file" name="file"/>
查看更多
登录 后发表回答