个性化文件上传弹出窗口

时间:2011-05-02 09:31:35

标签: html

<input type="file" name="somename" />

我想通过在文件名文件中显示一条消息来个性化弹出窗口。单击<input>类型文件的浏览按钮即可打开。

2 个答案:

答案 0 :(得分:0)

如果您正在谈论自定义标准浏览器<input type="file" ... />文件浏览窗口/界面,那么这是不可能的。

然而,你可以在Flash中重新创建自己的界面/解决方案,但这远远超出了这个问题的范围,而且可能不是最好的想法。

答案 1 :(得分:0)

捕获文件click元素上的<input>事件。然后,您可以使用alert()显示消息,或使用confirm()取消选项。使用preventDefault()可阻止显示文件上传对话框。

演示:http://jsfiddle.net/ThinkingStiff/AX2s9/

脚本:

document.getElementById( 'file' ).addEventListener( 'click', function ( event ) {
    if( !confirm( 'A message before the file dialog. Are you sure you want to upload a file?' ) ) {
        event.preventDefault();
    };
} );

HTML:

<input id="file" type="file" />
相关问题