为什么不't选择单选按钮时,文本区域将被禁用

Why doesn't the textarea become disabled when choosing radio button

本文关键字:区域 文本 单选按钮 选择 为什么不      更新时间:2023-09-26

给定一个带有2个单选按钮和一个文本区域的简单HTML页面,当选择"否"单选按钮时,我想禁用文本区域。但以下内容从未禁用文本区域。

<html>
<head>
<style>
.textwrapper
{
    border:2px solid #999999;
    margin:5px 0;
    padding:3px;
}
</style>
<script type="text/javascript">
function disableText () {
  if(document.getElementById("button2").checked) {
    document.getElementById("summary").disabled = true;
  }
  else {
   document.getElementById("summary").disabled = false;
 }
}
</script>
</head>
<body>
Enter plot summary
<input type="radio" name="button1" id="button1" checked onclick="disableText()"> Yes
<input type="radio" name="button1" id="button2" onclick="disableText()"> No <br>
Plot summary <textarea class="textwrapper" name="plot" id="summary"></textarea>
</body>
</html>

-将函数名称更改为disabledText,而不是disableText

-用()-function disabledText() { } 声明函数

http://jsfiddle.net/4bs1gnrj/