CSS3 - enabled和disabled

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
    input[type="text"]:enabled{
        background-color:gold;
    }
    input[type="text"]:disabled{
        background-color:dimgrey;
    }
</style>
</head>

<body>
    <script>
        function radio_change(){
            var radio1 = document.getElementById('radio1');
            var radio2 = document.getElementById('radio2');
            var text = document.getElementById('text');
            if(radio1.checked){
                text.disabled = "";
            }else{
                text.value = "";
                text.disabled = "disabled";
            }
        }
    </script>
    <input type="radio" id="radio1" name="radio" onchange="radio_change()" />可用
    <input type="radio" id="radio2" name="radio" onchange="radio_change()" />不可用
    <input type="text" id="text" disabled />

</body>
</html>

这里写图片描述

猜你喜欢

转载自blog.csdn.net/zjsfdx/article/details/79334850