字段集中提供的禁用时未禁用此按钮

时间:2018-12-05 05:45:47

标签: html internet-explorer

我正在跨浏览器网站上工作,我已申请

<fieldset disabled="disable">

但是该按钮仍然可以正常使用,只是它似乎已被禁用,而其他浏览器(例如chrome)则完全禁用了它们,这是什么原因以及如何解决?

这是示例代码...

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>tesying</title>
</head>
<body>
    <form>
        <fieldset disabled>
            <input type="button" value="enter" id="button" />
        </fieldset>
    </form>
    <script>
        var d = document.getElementById('button');
        d.onclick = function () {
            console.log("hi");
        }
    </script>
</body>
</html>

ps:我仍然希望在字段集中禁用该选项。

1 个答案:

答案 0 :(得分:0)

在Internet Explorer中,已禁用属性不适用于字段集

作为解决方法,您可以尝试参考以下示例。

<!doctype html>
<head>
<script>
function disableInputs(el) {
    var el = document.getElementById('example'),
        all = el.getElementsByTagName('input'),
        i;
    for (i = 0; i < all.length; i++) {
        all[i].disabled = true;
    }
}

</script>
<body onload="disableInputs('example')">

<fieldset>
<div id="example">
    <input type="text" name="ex1">
    <input type="text" name="ex2">
    <input type="text" name="ex3">
    <input type="button" value="submit">
</div>
</fieldset>

</body>
</html>

Internet Explorer中的输出:

enter image description here