简体   繁体   English

此时不允许对元素输入进行属性捕获

[英]Attribute capture not allowed on element input at this point

This line of code:这行代码:

<input name="img" type="file" accept="image/*" capture="camera" onchange="uploadImage(this, 75)" />

fails to pass the W3C HTML5 validator check:未能通过W3C HTML5 验证器检查:

在此处输入图片说明 I would appreciate anyone letting me know why the error from W3C (and any solution), given that the code works fine and it opens the camera for mobile devices.我很感激任何人告诉我为什么 W3C(和任何解决方案)的错误,因为代码工作正常并且它为移动设备打开了相机。

It was a bug in the validator.这是验证器中的一个错误。

Even when the capture attribute didn't, so far, make its way into the HTML spec , it has already the "W3C Recommendation" status ( HTML Media Capture ).到目前为止,即使capture属性还没有进入HTML 规范,它也已经具有“W3C 推荐”状态 ( HTML Media Capture )。 Therefore, it should have been included in the validator.因此,它应该已包含在验证器中。

On March 2018, an issue was raised in the W3C mailing list and a member of the validator team acknowledged it. 2018 年 3 月, W3C 邮件列表中提出了一个问题,验证者团队的一名成员承认了这一点。 It was fixed on March 21, 2020 .它已于20203 月 21 日修复。

If you want to know more about the correct syntax regarding HTML Media Capture, have a look at this article .如果您想了解有关 HTML Media Capture 的正确语法的更多信息,请查看这篇文章

 label.cameraButton { display: inline-block; margin: 1em 0; /* Styles to make it look like a button */ padding: 0.5em; border: 2px solid #666; border-color: #EEE #CCC #CCC #EEE; background-color: #DDD; } /* Look like a clicked/depressed button */ label.cameraButton:active { border-color: #CCC #EEE #EEE #CCC; } /* This is the part that actually hides the 'Choose file' text box for camera inputs */ label.cameraButton input[accept*="camera"] { display: none; }
 <!DOCTYPE html> <html> <body> <label class="cameraButton">📷 <input type="file" accept="image/*;capture=camera"> </label> </body> </html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM