[英]How to detect browser supports this HTML5 feature
我想檢測(使用javascript / jQuery)用戶的瀏覽器是否支持multiple
屬性來input type='file'
標簽。 HTML5的一項功能,可添加多個圖像。
<input type=file name="images" value=" " multiple=""/>
請建議我怎么做這個。
var i = document.createElement("input");
if (typeof i.multiple !== 'undefined') {
// supports multiple
}
你可以使用為此目的而開發的modernizr
。
您可以通過以下方式檢測對placeholder
功能的支持:
if (!Modernizr.input.placeholder) {
}
從Modernizr來源采取和編輯:
var inputElem = document.createElement('input');
var multipleSupport = !!(multiple in inputElem);
如果這是您唯一需要的,則無需包含完整的庫。
我建議你使用Modernizr javascript庫嗎? 這提供了一種檢查瀏覽器是否支持各種功能的方法。
你可以使用Modernizr ,它為你做了大量的這些測試。
但在這種情況下,測試非常簡單:
if (typeof document.createElement('input').multiple !== "undefined") {
// ... yes, it has it
}
元素上的所有其他新屬性也是如此。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.