close

當用php的for產生了許多的相同類別的按鈕與需要顯示內容DIV,這時依照原先的程式碼是不會有反應的

原先 修改後

 

<script>
        $(document).ready(function(){
            $(".Show").click(function(){
                $(".Div).show("slow");
                $(".Show).hide();
                $(".Hide).show();
            });
            $("#Hide").click(function(){
                status = $(this).attr("name");
                $(".Div).hide("slow");
                $(".Hide).hide();
                $(".Show).show();
            });
        });
    </script>

點選到類別SHOW會抓取他的name值,

抓取NAME值為相同之DIV來做顯示內容

<script>
        var status="";
        $(document).ready(function(){
            $(".Show").click(function(){
                status = $(this).attr("name");
                $(".Div[name='"+status+"']").show("slow");
                $(".Show[name='"+status+"']").hide();
                $(".Hide[name='"+status+"']").show();
            });
            $("#Hide").click(function(){
                status = $(this).attr("name");
                $(".Div[name='"+status+"']").hide("slow");
                $(".Hide[name='"+status+"']").hide();
                $(".Show[name='"+status+"']").show();
            });
        });
    </script>


 

arrow
arrow

    kkkelu1008 發表在 痞客邦 留言(0) 人氣()