[英]How to change default message “Please enter a value with a valid mimetype.” for HTML file input
I just came across the accept
attribute of <input type="file">
and i really like it as i see that i don't need to write seperate validation for input file type if i use this attribute. 我刚刚遇到了
<input type="file">
的accept
属性,我真的很喜欢它,因为我看到如果我使用此属性,则无需为输入文件类型编写单独的验证。 its very simple like 它非常简单
<input type="file" accept="image/*">
will accept only image files.. <input type="file" accept="image/*">
将仅接受图像文件。
<input type="file" accept="audio/*">
will accept only audio files.. <input type="file" accept="audio/*">
将仅接受音频文件。
<input type="file" accept="video/*">
will accept only video files.. <input type="file" accept="video/*">
将仅接受视频文件。
However i see that if i some how select a different file then i see an error message 但是我看到如果我通过某种方式选择其他文件,则会看到错误消息
Please enter a value with a valid mimetype.
i just want to know if it i can somehow change this error message and print it so something of my choice.. also is it possible to add some css to this error message ?? 我只想知道是否可以更改此错误消息并打印出来,以便我选择。.也可以向该错误消息添加一些CSS吗?
使用jQuery验证器的工作原理:
<input type="file" accept="image/*" data-rule-required="true" data-msg-accept="Your message" />
尝试使用一些JavaScript魔术(标记oninvalid
属性):
<input type="file" accept="image/*" oninvalid="setCustomValidity('Please, blah, blah, blah ')"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.