如何使用Jquery显示和隐藏复选框文本

Jquery on time show and hide check box text if checked show the text if unchecked remove the text.

I am Trying to show the selected check boxes text at left side,and hide it when unchecked this is my from code what i have tried:

<div class="products-row">
    <?php $tq=$conn->query("select * from os_tiffen where tiffen_status=1 order by id_tiffen ASC");
        while ($tiffen = $tq->fetch_assoc()) {
        ?>  
        <div class="col-md-3"> 
            <div class="foodmenuform row text-center">
                <input type="checkbox" id="<?php echo $tiffen['tiffen_image'];?>" hidden>
                <label for="<?php echo $tiffen['tiffen_image'];?>"><img src="img/tiffen/<?php echo $tiffen['tiffen_image']; ?>" alt="" class="img img-responsive" /></label>
                <h3 id="tiffenname"><?php echo $tiffen['tiffen_name'];?></h3>
            </div>
        </div>
    <?php }  ?>
</div>

And this is My Script:

$( document ).ready(function() {
var FoodMenu = $('input[type=checkbox]:checked').map(function(){
return $(this).next('h3').text();
}).get().join("<br>");
$("#selectedfood").html(FoodMenu);
});

And this is the place where i am showing the output:

<div class="related-row" id="FoodSelected">
    <h4 class="text-center">Food Selected</h4> 
    <ul class="nav nav-pills nav-justified">
        <li class="active"><a id="selectedfood"></a></li>
    </ul>    
</div>
查看全部
douwen7905
douwen7905
2016/10/05 10:09
  • css
  • php
  • html
  • javascript
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复