我有一个小程序,其中包含4个单选按钮,分别分为2个用于“ FromLocal”的单选按钮和2个用于“ FromServer”的单选按钮。 所以我试图在条件下隐藏单选按钮: 如果从“ FromLocal”中选择了任何单选按钮,则它将隐藏我已编写程序 HTML:
的“ FromServer”单选按钮。<div id ="radiobutton1" >
<strong>FromLocal:</strong>
<input type="radio" name="target" value= "BrowserDownload">BrowseLocal
<input type="radio" name="target" value="dumpToS3" > S3Remote
<br/>
</div>
<!-- <div> -->
<div id="textboxes" style="display: none" >
<strong>ACCESS_KEY_ID: </strong>
<input class="box" type="text" / > <br/>
<strong>ACCESS_SECRET_KEY: </strong>
<input class="box" type="text" /> <br/>
<strong>MAIL: </strong>
<input class="box" type="text" /> <br/>
</div>
<strong>FromServer:</strong>
<input type="radio" name="server" value="serverDownload" id ="radiobutton2" >ServerBrowseLocal
<input type="radio" name="server" value="serverdumpToS3"id ="radiobutton2" > ServerS3Remote
JS:
$("input[name='target']").on('change',function(){
if($(this).val() == "dumpToS3")
$('#textboxes').show('slow');
else
$('#textboxes').hide();
});
$(function() {
if ($('#radiobutton2').is(':checked'))
$('#radiobutton1').hide();
else if ($('#radiobutton1').is(':checked'))
$('#radiobutton2').hide();
});
这是我要运行它的网站链接:
http://jsfiddle.net/y92kuzcL/29/
我已经尝试过,但是不知道为什么它不起作用,也许我编写的代码不正确。 请帮助我如何获得它。
谢谢。
答案 0 :(得分:4)
这会在单击其他两个单选按钮(服务器/本地)时隐藏其他两个单选按钮(本地/服务器)
$("#radiobutton1 > input").change(function(){$("#server").hide()})
$("#server > input").change(function(){$("#radiobutton1").hide()})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id ="radiobutton1" >
<strong>FromLocal:</strong>
<input type="radio" name="target" value= "BrowserDownload">BrowseLocal
<input type="radio" name="target" value="dumpToS3" > S3Remote
<br/>
</div>
<!-- <div> -->
<div id="textboxes" style="display: none" >
<strong>ACCESS_KEY_ID: </strong>
<input class="box" type="text" / > <br/>
<strong>ACCESS_SECRET_KEY: </strong>
<input class="box" type="text" /> <br/>
<strong>MAIL: </strong>
<input class="box" type="text" /> <br/>
</div>
<div id="server">
<strong>FromServer:</strong>
<input type="radio" name="server" value="serverDownload" id ="radiobutton2" >ServerBrowseLocal
<input type="radio" name="server" value="serverdumpToS3"id ="radiobutton2" > ServerS3Remote
</div>