选中复选框时 show/hide a div 的方法故障排除
Troubleshooting a method to show/hide a div when a checkbox is checked
所以我有以下 HTML 复选框代码和一个隐藏的 div 包含一个文本区域,我需要在选中该复选框时显示该文本区域。
HTML
<input type="checkbox" name="q3resp4" value="1" onchange="valueChanged()"/> Other entity (specify):<br>
<div style="display: none;" id="q3othertxt">
<textarea rows="4" cols="50" id="q7resp"></textarea>
</div>
JAVASCRIPT
<script type="text/javascript">
function valueChanged()
{
if($('.q3resp4').is(":checked"))
$(".q3othertxt").show();
else
$(".q3othertxt").hide();
}
</script>
我对这两种语言都不流利,所以我可能会在这里犯一些新手错误,但我尝试的每个 script/code 片段都没有给我结果。因此,在进行了大约 90 分钟的研究之后,我将求助于一个简单的问题。
感谢大家的帮助。
您 jquery 选择器中的点将通过 class 匹配,而不是 ID 或名称。
function valueChanged()
{
if($("input[name='q3resp4']").is(":checked"))
$("#q3othertxt").show();
else
$("#q3othertxt").hide();
}
所以我有以下 HTML 复选框代码和一个隐藏的 div 包含一个文本区域,我需要在选中该复选框时显示该文本区域。
HTML
<input type="checkbox" name="q3resp4" value="1" onchange="valueChanged()"/> Other entity (specify):<br>
<div style="display: none;" id="q3othertxt">
<textarea rows="4" cols="50" id="q7resp"></textarea>
</div>
JAVASCRIPT
<script type="text/javascript">
function valueChanged()
{
if($('.q3resp4').is(":checked"))
$(".q3othertxt").show();
else
$(".q3othertxt").hide();
}
</script>
我对这两种语言都不流利,所以我可能会在这里犯一些新手错误,但我尝试的每个 script/code 片段都没有给我结果。因此,在进行了大约 90 分钟的研究之后,我将求助于一个简单的问题。
感谢大家的帮助。
您 jquery 选择器中的点将通过 class 匹配,而不是 ID 或名称。
function valueChanged()
{
if($("input[name='q3resp4']").is(":checked"))
$("#q3othertxt").show();
else
$("#q3othertxt").hide();
}