代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>无标题</title>
<link type="text/css" rel="stylesheet" href="test.css"/>
<style type="text/css">
input[type="text"]:enabled {
background: rgba(255, 176, 38, 0.5);
}
input[type="text"]:disabled {
background: rgba(35, 23, 23, 0.5);
}
</style>
</head>
<body>
<script type="text/javascript">
function r() {
var r1 = document.getElementById("r1");
var r2 = document.getElementById("r2");
var r3 = document.getElementById("r3");
if (r1.checked) {
r3.disabled = "";
} else {
r3.disabled = "disabled";
}
}
</script>
<input type="radio" name="ra" id="r1" onchange="r()"/>可用
<input type="radio" name="ra" id="r2" onchange="r()" checked/>不可用
<input type="text" id="r3" disabled/>
</body>
</html>
运行结果简要展示: