Javascript 两个单选按钮,一个textarea和一个数字框,当radio1为是和/或2为否时,如何检查textarea是否已填充

Javascript 两个单选按钮,一个textarea和一个数字框,当radio1为是和/或2为否时,如何检查textarea是否已填充,javascript,php,jquery,html,Javascript,Php,Jquery,Html,这是收音机和文本区等 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="pos

这是收音机和文本区等

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" />
这使得文本区域在1为是和/或2为否时打开,唯一的问题是如果您将收音机更改为no1/yes2(这应该是文本区域不显示的唯一方式),它将保持在那里,我将如何使它仅在1为是和/或2为否之外的内容为真时显示,如果改变了,它就会消失,如果不是真的,它就不会出现

接下来我想做的是,当1=是或/和2=否时,需要填写文本区域

大部分情况下,您可以忽略丢失的数值


这就是你想要实现的吗?

是的,我理解并忽略了很多php,因为那里的大部分php只是与页面的其余部分相关,这些代码是关于它如何与页面上的其他内容交互的,也就是说,这只是一个随机的其他内容。如果实际页面上有其他代码,哈哈好的,是的,很抱歉这是一个HTML在实际页面中稍微更容易理解,但是是的,在那里更改了jqok,我想现在文本区域消失了,谢谢!所以你知道如何检查它是否只有在显示时才填写吗?如果你想检查
textarea
是否为空,你可以使用这样的方法:
if($('textarea').val()!=“”
$(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').is(':checked')){
        $(".comments").show();
        $(".returncomments").show();
    }
    else{
        $(".comments").hide();
        $(".returncomments").hide();
    }
});
 $("#putback2").click(function () {
        $(".comments").show();
        $(".returncomments").show();
});
$("#putback1").click(function () {      
    if($('#missing2').is(':checked')){
        $(".comments").hide();
        $(".returncomments").hide();
    }
    else{
        $(".comments").show();
        $(".returncomments").show();
    }
});});
var itemMissing = false
  , itemPluggedIn = true;

function updateCommentsDisplay(itemMissing, itemPluggedIn) {
    if(itemMissing || !itemPluggedIn) {
        $('#comments').show();
    } else {
        $('#comments').hide();
    }
}

$('#nb-of-missing-items-field').hide();
updateCommentsDisplay(itemMissing, itemPluggedIn);

$('#missing input[name="missing-items"]').on('change', function () {
    if(this.value === 'Yes') {
        $('#nb-of-missing-items-field').show();
        itemMissing = true;
    } else {
        $('#nb-of-missing-items-field').hide();
        itemMissing = false;
    }

    updateCommentsDisplay(itemMissing, itemPluggedIn);
});

$('#plugged-in input[name="plugged-in-items"]').on('change', function () {
    if(this.value === 'Yes') {
        itemPluggedIn = true;
    } else {
        itemPluggedIn = false;
    }

    updateCommentsDisplay(itemMissing, itemPluggedIn);
});