[英]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.