[英]How to check when radio 1 radio button is checked and the second radio button is also checked it does one thing but if not it does another
我有2个单选按钮,1个文本区域和1个数字区域(类型=“数字”输入并不真正知道该怎么称呼)。
if(mysql_num_rows($canview) > 0) { ?>
<!-- Questions on return send all this to database then to place where dept. heads can see it-->
<div id = "returnform" >
<form action="" method="post">
<h4>Are any of the item(s) missing?</h4>
Yes<input type ="radio" name ="missing" id = "missing1" value = "Yes" required>
No<input type ="radio" name ="missing" id = "missing2" value = "No" >
<div class = "lossnum">
<input type="number" name="lossnum" id = "lossnum" placeholder="0">
</div>
<h4>Was every item put back/plugged in correctly?</h4>
Yes<input type ="radio" name ="putback" id = "putback1" value = "Yes" required>
No<input type ="radio" name ="putback" id = "putback2" value = "No">
<div class = "returncomments">
<h4>what happened?</h4>
<textarea name="comments"></textarea>
</div>
</div>
<input name="item_id" type="hidden" value="<?php echo $item->get_id(); ?>" />
<h4>Are you sure you want to return these <?php echo $item->get_name(); ?>? </h4>
<input type="submit" id="submit" name="submit" value="Return" />
<?php
}elseif(mysql_num_rows($canview) == 0 && $success == false) { ?>
<input name="item_id" type="hidden" value="<?php echo $item->get_id(); ?>" />
我已经使Lostnum(数字计数器)在它断断续续地正常工作,我需要做的是使textarea仅在单选按钮1等于“是”或单选按钮2等于“否”或两者都为时显示。发生,现在,如果您单击单选按钮1(因为是,它会出现),但是如果将其更改为否,它不会消失,因此我需要进行更改。
$(document).ready(function () {
$(".lossnum").hide();
$(".comments").hide();
$(".returncomments").hide();
$(".commentup").hide();
$("#missing1").click(function () {
$(".lossnum").show();
$(".comments").show();
$(".returncomments").show();
});
$("#missing2").click(function () {
$(".lossnum").hide();
if($('#putback2').prop('checked', value)){
$(".comments").show();
$(".returncomments").show();
}
else{
$(".comments").hide();
$(".returncomments").hide();
}
});
$("#putback2").click(function () {
$(".comments").show();
$(".returncomments").show();
});
$("#putback1").click(function () {
if($('#missing2').prop('checked', value)){
$(".comments").hide();
$(".returncomments").hide();
}
else{
$(".comments").show();
$(".returncomments").show();
}
}); });
同样如果你们都知道要这么做,那么仅当选择了某些单选按钮时,才需要或选中它(例如,如果不放回,则必须填写文本区域,和/或如果缺少,则必须执行相同操作)
这是一个jsfiddle的http://jsfiddle.net/SameB/L7et15du/
您需要在单选按钮的单击处理程序中更正您的if
条件。 您正在使用$('#putback2').prop('checked', value)
设置单选按钮值$('#putback2').prop('checked', value)
但是您需要检查是否已选中,请参见以下代码
$("#missing2").click(function () {
$(".lossnum").hide();
if($('#putback2').is(':checked')){//correct here
$(".comments").show();
$(".returncomments").show();
}
else{
$(".comments").hide();
$(".returncomments").hide();
}
});
同样需要做回击1
$("#putback1").click(function () {
if($('#missing2').is(':checked')){
$(".comments").hide();
$(".returncomments").hide();
}
else{
$(".comments").show();
$(".returncomments").show();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.