0

我使用下面的代码来自定义文件输入类型,

<form class="example" action="#">
<!--<input type="file" class="required-entry filename file" name="filename[]" />-->
<div class="fileinputs">
    <input type="file" class="file hidden">
<div class="fakefile"><input><img src="ravi/images/button_select.gif" /></div></div>
</form>

样式.css

<style type="text/css">
    body{
        color: black;
        font-family: arial;
        font-size: 13px;
    }
form.example input {
    background: url('ravi/images/input_boxes.gif') no-repeat 0 -58px;
    border: none;
    width: 241px;
    height: 20px;
    padding-left: 3px;
    padding-top: 3px;
}

form.example input:focus {
    background-color: transparent;
}

form.example div.fileinputs {
    position: relative;
    height: 30px;
    width: 300px;
}

form.example input.file {
    width: 300px;
    margin: 0;
}

form.example input.file.hidden {
    position: relative;
    text-align: right;
    -moz-opacity:0 ;
    filter:alpha(opacity: 0);
    opacity: 0;
    z-index: 2;
}

form.example div.fakefile {
    position: absolute;
    top: 0px;
    left: 0px;
    width: 350px;
    padding: 0;
    margin: 0;
    z-index: 1;
    line-height: 90%;
}

form.example div.fakefile input {
    margin-bottom: 5px;
    margin-left: 0;
}

</style>

页面显示如下,

在此处输入图像描述

当我单击选择按钮时,会出现浏览文件夹,然后我选择图像文件。但在输入文件中,上传的图像标题未显示..

我从http://www.quirksmode.org/dom/inputfile.html

问题是什么?

4

1 回答 1

0

您需要按照您引用的页面上的说明添加 JavaScript 代码。

如果您在测试中使用的代码基本上由您发布的 HTML 和 CSS 代码组成,那么您使用的是页面上描述的方法的“纯 CSS”版本。在解释基本版本的编号列表中,它也使用 JavaScript,第 5 项描述了“纯 CSS”版本中缺少的功能。该功能是“当用户选择一个文件时,可见的虚假输入字段应显示该文件的正确路径”。

(它实际上不会显示正确的路径。出于安全原因,浏览器不会透露真实路径。但它们确实让您显示文件名部分。)

于 2012-06-09T13:15:12.930 回答