简体   繁体   English

为什么选择单选按钮时不会禁用文本区域

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

Given a simple HTML page with 2 radio buttons and a textarea, I want to disable the textarea when the "No" radio button is selected. 给定一个带有2个单选按钮和一个textarea的简单HTML页面,我想在选择“ No”单选按钮时禁用该textarea。 But the following never disables the 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>

A couple things 几件事

-Change your function name to disabledText - not disableText -将函数名称更改为disabledText而不是disableText

-Declare functions with () - function disabledText() { } -使用()声明函数-function function disabledText() { }

http://jsfiddle.net/4bs1gnrj/ http://jsfiddle.net/4bs1gnrj/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM