HTML文件输入接受问题

时间:2016-06-01 10:07:43

标签: android html

我正在创建一个基于Web的Android应用程序,我正在尝试在html部分添加文件过滤器。

<button id="btnOpenChrome" title="Open file" style="position:relative;overflow:hidden;"><img id="imgOpenChrome" src="images/OpenFile.png" alt="Open File">
    <input type="file" id="file" accept="text/rtf,text/html,text/plain,application/pdf" style="position:absolute;top:0;bottom:0;left: 0;right:0;opacity: 0.001"> </button>

这就是我所拥有的,它应该只允许打开rtf,txt,html和pdf文件。然而它根本不起作用,它过滤所有文件,如果我只留下一个例如:

accept="text/rtf"

过滤器工作并且只允许rtf文件,为什么逗号会破坏这行代码?我看到他们在其他应用程序中使用文件过滤器。

4 个答案:

答案 0 :(得分:1)

您可以使用下一个代码:

<p>This button will open ONLY rft, html, plain text and pdf</p>

<button id="btnOpenChrome" title="Open file" style="position:relative;overflow:hidden;"><img id="imgOpenChrome" src="images/OpenFile.png" alt="Open File">
    <input type="file" id="file" accept=".rtf,.html,.plain,.pdf" style="position:absolute;top:0;bottom:0;left: 0;right:0;opacity: 0.001">
  </button>
  </body>

答案 1 :(得分:0)

我发现以下适用于.rtf文件而不是MIME类型:

<input type="file" name="file" accept='.rtf'>

以及其他类型的文件

<input type="file" name="file" accept='.rtf,.doc,.docx,.pdf'>

答案 2 :(得分:0)

这可能无法解决您的疑问,但您只需编写代码来检查所需的扩展程序。

<input type="file" id="file" onchange="CheckFile(this)"/>

在输入标签

中添加此功能
struct list_element {
    int value;
    struct list_element *next;
};

typedef struct list_element listelement;

答案 3 :(得分:0)

下面的代码应该起作用。 Bur无论如何&#34;接受&#34;属性不是一种好的验证方式。最好在服务器端进行一些检查。

<button id="btnOpenChrome" title="Open file" style="position:relative;overflow:hidden;"><img id="imgOpenChrome" src="images/OpenFile.png" alt="Open File">
    <input type="file" id="file" accept=".rtf,.html,.plain,.pdf" style="position:absolute;top:0;bottom:0;left: 0;right:0;opacity: 0.001">
</button>