dongluanan7163 2014-01-30 05:12
浏览 79
已采纳

jQuery隐藏/显示包含php include的div

Let me first say I am 98% positive I am going about this the wrong way.

First time poster, be gentle. I am working on a website where I want a primitive admin portal back-end where the site can be managed in a single .php page. I have two columns, on the left is a series of stacked nav-pills and on the right is a PHP form to edit site content. Depending on which nav-pill is clicked, the right hand side will display a corresponding PHP form. I need the jQuery function to .empty() the container div called "admin-div" and .toggle() the proper div based on id. The jQuery doesn't seem to be working, and I'm having a hard time grasping why. I am entirely new at jQuery and I'm still a student, so forgive any obvious oversights. Code below for reference. Thanks in advanced! (Sorry if this is off-topic or not a valid question / post, I'm new).

            $(document).ready(function(){
            $("#geo-btn").click(function(){
            $("#admin-div").empty();
            $("#geo-div").toggle();
            });
        });     

        $(document).ready(function(){
            $("#school-btn").click(function(){
            $("#admin-div").empty();
            $("#school-div").toggle();
            });
        });



<div class="container">
<ul class="nav nav-pills nav-stacked nav-justified">
    <label>Edit Geographic Information</label>
        <li><button id="geo-btn" class="btn btn-warning" >Geography</button></li><br>
        <li><button id="school-btn" class="btn btn-warning" >Schools</button></li><br>
</ul>
<div class="admin-div">
    <div id="geo-div" align="left" class="span8">
        <?php
            require("geo.inc.php");
        ?>
    </div>
    <div id="school-div" align="left" class="span8">
        <?php
            require("school.inc.php");
        ?>
    </div>
</div>

  • 写回答

2条回答 默认 最新

  • duanmingting9544 2014-01-30 05:17
    关注

    Is this what you are trying to do:

    <ul class="nav nav-pills nav-stacked nav-justified">
        <label>Edit Geographic Information</label>
            <li><button category="geo"  class="btn btn-warning" >Geography</button></li><br>
            <li><button category="school" class="btn btn-warning" >Schools</button></li><br>
    </ul>
    <div id="admin-div">
        <div id="geo-div" align="left" class="span8">
            <?php
                require("geo.inc.php");
            ?>
        </div>
        <div id="school-div" align="left" class="span8" style="display: none;">
            <?php
                require("school.inc.php");
            ?>
        </div>
    </div>
    
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type="text/javascript">
         $(document).ready(function()
         {
            $(".btn").click(function()
            {
                var category = $(this).attr("category")
    
                $("#admin-div div").hide();
                $("#"+category+"-div").fadeIn();
            });
        });   
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)