隐藏类如果它有输入值" X"

时间:2014-05-17 15:41:37

标签: php css

如何使用CSS + PHP隐藏div参数特定卖家(<div class="seller">)?如果我按照以下方式访问网站,则每个卖家都有ID <input type="hidden" value="1" name="seller_id">

website.com/?hideseller=2

CSS代码:

<div class="seller-list" id="seller-list">
        <div class="head">Sellers List </div>
        <div class="title">
            <span class="lable" style="width:100px">Price</span>
            <span class="lable">Seller Information</span>
            <span class="lable">Available Products</span>
            <span class="lable"></span>
        </div>
                <div class="seller">
            <form action="checkout/cart/add/uenc/aHR0cDovL3ByaWNlZ290by5jb20vYXBwbGUtaXBob25lLTVzLWdvbGQtMTZnYi11bmxvY2tlZC5odG1s/product/35720/form_key/2sprf498VYBVPIw0/" method="">
                <input type="hidden" value="1" name="seller_id">
                <span class="data" style="width:100px;">
                    <span class="price">$100.00</span>
                </span>
                <span class="data">
                    <a href="profile/TestUser" title="Visit Profile">
                        <img src="/media/avatar/noimage.png">
                        <div class="mp_landing_hover">
                            <span>TestUser</span>
                        </div>
                    </a>
                </span>
                <span class="data">10</span>
                <span class="data" style="display:none;"> Qty : <input style="width:20px;" type="text" value="1" name="qty"></span>
                <span class="data">
                <input type="submit" title="Add to Cart" class="addtocart" value="Add to Cart"></span>
            </form>
        </div>
                <div class="seller">
            <form action="aHR0cDovL3ByaWNlZ290by5jb20vYXBwbGUtaXBob25lLTVzLWdvbGQtMTZnYi11bmxvY2tlZC5odG1s/product/35720/form_key/2sprf498VYBVPIw0/" method="">
                <input type="hidden" value="2" name="seller_id">
                <span class="data" style="width:100px;">
                    <span class="price">$511.00</span>
                </span>
                <span class="data">
                    <a href="seller/profile/Test2" title="Visit Profile">
                        <img src="media/avatar/noimage.png">
                        <div class="mp_landing_hover">
                            <span>Test2</span>
                        </div>
                    </a>
                </span>
                <span class="data">1111</span>
                <span class="data" style="display:none;"> Qty : <input style="width:20px;" type="text" value="1" name="qty"></span>
                <span class="data">
                <input type="submit" title="Add to Cart" class="addtocart" value="Add to Cart"></span>
            </form>
        </div>
            </div>

1 个答案:

答案 0 :(得分:0)

如果您想要隐藏该特定class="seller",首先需要获取$_GET['hideseller'] ID,然后使用$.each()进行循环播放。考虑这个例子:

<div class="seller-list" id="seller-list">
<div class="head">Sellers List </div>
<div class="title">
    <span class="lable" style="width:100px">Price</span>
    <span class="lable">Seller Information</span>
    <span class="lable">Available Products</span>
    <span class="lable"></span>
</div>
        <div class="seller">
    <form action="checkout/cart/add/uenc/aHR0cDovL3ByaWNlZ290by5jb20vYXBwbGUtaXBob25lLTVzLWdvbGQtMTZnYi11bmxvY2tlZC5odG1s/product/35720/form_key/2sprf498VYBVPIw0/" method="">
        <input type="hidden" value="1" name="seller_id">
        <span class="data" style="width:100px;">
            <span class="price">$100.00</span>
        </span>
        <span class="data">
            <a href="profile/TestUser" title="Visit Profile">
                <img src="/media/avatar/noimage.png">
                <div class="mp_landing_hover">
                    <span>TestUser</span>
                </div>
            </a>
        </span>
        <span class="data">10</span>
        <span class="data" style="display:none;"> Qty : <input style="width:20px;" type="text" value="1" name="qty"></span>
        <span class="data">
        <input type="submit" title="Add to Cart" class="addtocart" value="Add to Cart"></span>
    </form>
</div>
        <div class="seller">
    <form action="aHR0cDovL3ByaWNlZ290by5jb20vYXBwbGUtaXBob25lLTVzLWdvbGQtMTZnYi11bmxvY2tlZC5odG1s/product/35720/form_key/2sprf498VYBVPIw0/" method="">
        <input type="hidden" value="2" name="seller_id">
        <span class="data" style="width:100px;">
            <span class="price">$511.00</span>
        </span>
        <span class="data">
            <a href="seller/profile/Test2" title="Visit Profile">
                <img src="media/avatar/noimage.png">
                <div class="mp_landing_hover">
                    <span>Test2</span>
                </div>
            </a>
        </span>
        <span class="data">1111</span>
        <span class="data" style="display:none;"> Qty : <input style="width:20px;" type="text" value="1" name="qty"></span>
        <span class="data">
        <input type="submit" title="Add to Cart" class="addtocart" value="Add to Cart"></span>
    </form>
</div>
    </div>

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

    var particular_id = '<?php echo isset($_GET["hideseller"]) ? $_GET["hideseller"] : "" ?>';
    if(particular_id != '') {
        $('.seller').each(function(){
            // traverse then compare
            if($(this).children().children('input[name="seller_id"]').attr('value') == particular_id) {
                $(this).hide();
            }

        });
    }

});
</script>