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

Javascript 为什么';t选择单选按钮时文本区域将被禁用,javascript,html,Javascript,Html,给定一个包含两个单选按钮和一个textarea的简单HTML页面,我想在选择“否”单选按钮时禁用textarea。但是下面的内容从未禁用textarea <html> <head> <style> .textwrapper { border:2px solid #999999; margin:5px 0; padding:3px; } </style> <script type="text/javascript"&

给定一个包含两个单选按钮和一个textarea的简单HTML页面,我想在选择“否”单选按钮时禁用textarea。但是下面的内容从未禁用textarea

<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>

.textwrapper
{
边框:2个实心#999999;
保证金:5px0;
填充:3倍;
}
函数禁用文本(){
if(document.getElementById(“button2”).选中){
document.getElementById(“summary”).disabled=true;
}
否则{
document.getElementById(“summary”).disabled=false;
}
}
输入绘图摘要
对
否
情节摘要
几件事

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

-使用
()
-
函数disabledText(){}


将脚本移动到正文末尾使用onchange()而不是onclick()@tyme:为什么?这个函数应该在它所在的地方可以访问,不是吗?语法错误和拼写错误当然是另一回事。我向大家道歉——我上传了错误的文件:(.correction——你们中的许多人提到的关于语法的问题——现在已经在原始问题中进行了编辑。David Thomas——也给了你们一些放弃投票的机会。:-)tymeJV——我会为我的拼写错误向你们表示感谢。它起作用了--我答应明天多喝点咖啡…:-)