gpt4 book ai didi

html - 如何动态更改输入类型文件的标题?

转载 作者:太空宇宙 更新时间:2023-11-04 14:03:58 26 4
gpt4 key购买 nike

我想实现一种不同类型的输入文件,所以我使用了更改默认文件的 css 和 html 选项。所以我有以下 html 代码:

<div class="fileinputs">&nbsp;
<input type="file" class="file" id="file" name="file" title="There aren't any files chosen yet." style="width:270px;"/>
<div class="fakefile">
<input tyle="button" name="button" value="Choose the file you want (click)" />
</div>
</div>

然后,CSS代码:

div.fileinputs {position: relative;}
div.fakefile {
position: absolute;
top: 0px;
left: 0px;
z-index: 1;
}
input.file {
position: relative;
text-align: right;
-moz-opacity:0 ;
filter:alpha(opacity: 0);
opacity: 0;
z-index: 2;
}

一切看起来都很好,当我将鼠标悬停在输入上时,它会显示我用 html 编写的标题。但是我希望它在我选择一个文件后改变,以显示我选择的文件的名称。我怎样才能做到这一点?提前致谢。

最佳答案

试试这段代码:

DEMO

JS:

 $('input').change(function(){
$(this).attr('title',($(this).val()));
});

关于html - 如何动态更改输入类型文件的标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21279105/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com