gpt4 book ai didi

javascript - 单击 "Yes"单选按钮时显示文本区域,默认情况下或单击 "No"单选按钮时保持隐藏状态

转载 作者:行者123 更新时间:2023-12-01 03:57:30 25 4
gpt4 key购买 nike

我有这个 html 代码,并试图弄清楚当我仅选择"is"单选按钮时如何使用 java 脚本创建文本区域框。默认情况下或选择“否”时,该文本区域应保持隐藏状态。

<table class="table100" width="150%" cellspacing="2" cellpadding="2">
<tr>
<td class="data_yy yyy1">
<input type="radio" name="jack" id="jack" value="Y" onclick="hideShowJacks('Y');"/><label>Yes</label>
<input type="radio" name="jack" id="jack" value="N" checked onclick="hideShowJacks('N');"/><label>No</label>
</td>
<td class="data_xx xxx1"> Are you in high school?</td>
</tr>

最佳答案

你可以这样做:

function hideShowJacks(val) {
if (val == "Y") {
$("#area").show();
} else {
$("#area").hide();
}
}
#area {
display:none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="table100" width="150%" cellspacing="2" cellpadding="2">
<tr>
<td class="data_yy yyy1">
<input type="radio" name="jack" id="jack" value="Y" onclick="hideShowJacks('Y');"/><label>Yes</label>
<input type="radio" name="jack" id="jack" value="N" checked onclick="hideShowJacks('N');"/><label>No</label>
</td>
<td class="data_xx xxx1"> Are you in high school?</td>
</tr>
</table>
<textarea id="area"></textarea>

如果您更喜欢使用 Javascript 而不是 jQuery:

function hideShowJacks(val) {
if (val == "Y") {
document.getElementById("area").style.display = "block";
} else {

document.getElementById("area").style.display = "none";
}
}
#area {
display:none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="table100" width="150%" cellspacing="2" cellpadding="2">
<tr>
<td class="data_yy yyy1">
<input type="radio" name="jack" id="jack" value="Y" onclick="hideShowJacks('Y');"/><label>Yes</label>
<input type="radio" name="jack" id="jack" value="N" checked onclick="hideShowJacks('N');"/><label>No</label>
</td>
<td class="data_xx xxx1"> Are you in high school?</td>
</tr>
</table>
<textarea id="area"></textarea>

关于javascript - 单击 "Yes"单选按钮时显示文本区域,默认情况下或单击 "No"单选按钮时保持隐藏状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61944220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com