A file input button for all browsers, is this possible?

后端 未结 4 619
死守一世寂寞
死守一世寂寞 2020-12-02 13:42

Is it possible to use uploadify to allow any user to select a file from the file dialogue and insert it into the file input element of a form? I only need t

相关标签:
4条回答
  • 2020-12-02 14:20

    If it's only the upload button you want to style, why can't you use CSS? That should work across all browsers.

    If you put your code on jsFiddle, I can tell you more about what you can do.

    0 讨论(0)
  • 2020-12-02 14:25

    Your best bet in that case would be to use a flash uploader. This would introduce a complete separate control and would have no dependency on the browser. There are plenty of them on the net. Here's one : http://swfupload.org/

    0 讨论(0)
  • 2020-12-02 14:28

    The simple way to use a "label" tag and "for" property. Like this http://jsfiddle.net/Txrs6/ but in this case we don't see a chosen file. CODE

    <label for="inputFile" class="col-sm-3" style="padding-left: 0px;"><a class="btn btn-info">Выбрать...</a></label>`
    
    <input style="display: none;" type="file" id="inputFile">
    

    Another way with js http://jsfiddle.net/PZ5Ep/

    0 讨论(0)
  • 2020-12-02 14:34

    I can't remember the source of the technique but this seems to be cross-browser. Tested in:

    • Google Chrome 9
    • FireFox 3.6
    • Internet Explorer 6-9
    • Opera 10
    • Safari for Windows

    Here is the complete code:

    HTML:


    <div>
        <button><!-- this is skinnable -->Pick a file ...</button>
        <input type="file" />
    </div>
    

    CSS:


    div
    {
        position:relative;
        width: 100px;
        height: 30px;
        overflow:hidden;
    }
    
    div button
    {
        position: absolute;
        width: 100%;
        height: 100%;
    }
    
    div input
    {
        font: 500px monospace; /* make the input's button HUGE */
        opacity:0; /* this will make it transparent */
        filter: alpha(opacity=0); /* transparency for Internet Explorer */
        position: absolute;  /* making it absolute with z-index:1 will place it on top of the button */
        z-index: 1;
        top:0;
        right:0;
        padding:0;
        margin: 0;
    }
    

    The idea is to make the <input type="file" /> transparent and place it on top of some style-able content (a <button> in this case). When the end user clicks the button she will actually click the <input type="file" />.

    0 讨论(0)
提交回复
热议问题