如何检查浏览器对HTML5表单属性的支持? [英] How to check browser support for HTML5 form attributes?

查看:70
本文介绍了如何检查浏览器对HTML5表单属性的支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查浏览器是否支持 formtarget 表单属性?

How can I check if a browser supports the formtarget or the form attribute?

Modernizr在这里没有帮助,我甚至无法在网络上找到有关浏览器当前状态表单支持的内容。虽然快速测试显示除了IE 9之外的所有当前浏览器都支持它们。

Modernizr is no help here and I couldn't even find something on the web on the current state of form support in browsers. Although a quick test revealed all current browsers except IE 9 do support them.

那么如何检查浏览器是否处理表格* 属性?

So how can I check if a browser handles the form* attributes?

推荐答案

输入上的表单属性是一个特例。它在HTML5功能之前用于引用父表单,但现在它也被用作属性,因此你会在IE上出现误报。

The form attribute on input is a special case. It was used before the HTML5 feature, to reference the parent form, but now it's used as an attribute as well, so you will have false positives on IE.

有检查功能,但它涉及与DOM的交互,这可能会影响性能,但无论如何你去。希望它有所帮助。

There is a checking function but it involves interaction with DOM which will probably affect performance, but here you go anyway. Hope it helps.

function testInputFormSupport() {
    var input = document.createElement('input'),
         form = document.createElement('form'),
         formId = 'test-input-form-reference-support';
    // Id of the remote form
    form.id = formId;
    // Add form and input to DOM
    document.body.appendChild(form);
    document.body.appendChild(input);
    // Add reference of form to input
    input.setAttribute('form', formId);
    // Check if reference exists
    var res = !(input.form == null);
    // Remove elements
    document.body.removeChild(form);
    document.body.removeChild(input);
    return res;
}

这篇关于如何检查浏览器对HTML5表单属性的支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆