Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery-在页面加载时加载这两个元素_Javascript_Jquery_Html - Fatal编程技术网

Javascript JQuery-在页面加载时加载这两个元素

Javascript JQuery-在页面加载时加载这两个元素,javascript,jquery,html,Javascript,Jquery,Html,我使用了一些jQuery来隐藏和显示页面上的某些元素。但是,在页面加载时,它们都会显示。然后,当您与菜单/选项交互时,它会按预期工作 我不想让它们在我以前使用过这段代码时都显示出来,但我已经添加了 任何帮助都将不胜感激 以下是行为: 以下是jQuery: <script type="text/javascript"> $(document).ready(function () { $('#menu').on('click', 'a', function (e) {

我使用了一些jQuery来隐藏和显示页面上的某些元素。但是,在页面加载时,它们都会显示。然后,当您与菜单/选项交互时,它会按预期工作

我不想让它们在我以前使用过这段代码时都显示出来,但我已经添加了

任何帮助都将不胜感激

以下是行为:

以下是jQuery:

<script type="text/javascript">
$(document).ready(function () {
    $('#menu').on('click', 'a', function (e) {
        $('.current').not($(this).closest('li').addClass('current')).removeClass('current');
        $('.pbox:visible').hide(600);
        $('.pbox[id=' + $(this).attr('data-id') + ']').show(600);
        e.preventDefault();
    });
});
</script>

$(文档).ready(函数(){
$(“#菜单”)。在('click','a',函数(e)上{
$('.current')。不是($(this.closest('li')。addClass('current'))。removeClass('current');
$('.pbox:visible').hide(600);
$('.pbox[id='+$(this.attr('data-id')+']).show(600);
e、 预防默认值();
});
});
以下是html:

<ul id="menu" >
                        <li class="current profile-menu center"><a href="#" class="profile-links" data-id="div1"><h2 class="profile-menu">Info</h2></a></li>
                        <h2 class="profile-menu" style="padding-left:6px;padding-right:6px;font-size:15px;"><span>|</span></h2>
                        <li class="profile-menu center"><a href="#" class="profile-links" data-id="div2"><h2 class="profile-menu">Stats</h2></a></li>
                    </ul>

<div class="pbox" id="div1">
                        <table class="stat-list">
                            <tbody>
                                {% if driver.fullNationality %}
                                <tr>
                                    <th scope="row" class="stat-key">
                                        <span class="text">Nationality</span>
                                    </th>
                                    <td class="stat-value">{{ driver.fullNationality }}</td>
                                </tr>  
                                {% endif %} 
                                {% if driver.age %}
                                <tr>
                                    <th scope="row" class="stat-key">
                                        <span class="text">Age</span>
                                    </th>
                                    <td class="stat-value">{{ driver.age }}</td>
                                </tr>  
                                {% endif %}  
                                {% if driver.placeofbirth %}
                                <tr>
                                    <th scope="row" class="stat-key">
                                        <span class="text">Born</span>
                                    </th>
                                    <td class="stat-value">{{ driver.placeofbirth }}</td>
                                </tr>  
                                {% endif %} 
                                {% if driver.lives %}
                                <tr>
                                    <th scope="row" class="stat-key">
                                        <span class="text">Lives</span>
                                    </th>
                                    <td class="stat-value">{{ driver.lives }}</td>
                                </tr>  
                                {% endif %}
                                <tr>
                                    <th scope="row" class="stat-key">
                                        <span class="text">Height</span>
                                    </th>
                                    <td class="stat-value">5ft 11</td>
                                </tr>   
                                <tr>
                                    <th scope="row" class="stat-key">
                                        <span class="text">Weight</span>
                                    </th>
                                    <td class="stat-value">175lbs</td>
                                </tr> 
                                <tr>
                                    <th scope="row" class="stat-key">
                                        <span class="text">Highest race finish</span>
                                    </th>
                                    <td class="stat-value">1 (x64)</td>
                                </tr>       
                                <tr>
                                    <th scope="row" class="stat-key">
                                        <span class="text">Date of birth</span>
                                    </th>
                                    <td class="stat-value">07/01/1985</td>
                                </tr>   
                                <tr>
                                    <th scope="row" class="stat-key">
                                        <span class="text">Place of birth</span>
                                    </th>
                                    <td class="stat-value">Stevenage, England</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                        <div class="pbox" id="div2">                        
                            <table class="stat-list">
                                <tbody> 
                                    <tr>
                                        <th scope="row" class="stat-key">
                                            <span class="text">Team</span>
                                        </th>
                                        <td class="stat-value">Mercedes</td>
                                    </tr>     
                                    <tr>
                                        <th scope="row" class="stat-key">
                                            <span class="text">Wins</span>
                                        </th>
                                        <td class="stat-value">1</td>
                                    </tr>      
                                    <tr>
                                        <th scope="row" class="stat-key">
                                            <span class="text">Podiums</span>
                                        </th>
                                        <td class="stat-value">3</td>
                                    </tr>  
                                    <tr>
                                        <th scope="row" class="stat-key">
                                            <span class="text">Points</span>
                                        </th>
                                        <td class="stat-value">2730</td>
                                    </tr>   
                                    <tr>
                                        <th scope="row" class="stat-key">
                                            <span class="text">GP's entered</span>
                                        </th>
                                        <td class="stat-value">11</td>
                                    </tr>   
                                    <tr>
                                        <th scope="row" class="stat-key">
                                            <span class="text">Championships</span>
                                        </th>
                                        <td class="stat-value">0</td>
                                    </tr> 
                                    <tr>
                                        <th scope="row" class="stat-key">
                                            <span class="text">Highest race finish</span>
                                        </th>
                                        <td class="stat-value">1 (x64)</td>
                                    </tr>
                                    <tr>
                                        <th scope="row" class="stat-key">
                                            <span class="text">Highest grid position</span>
                                        </th>
                                        <td class="stat-value">1</td>
                                    </tr>        
                                </tbody>
                            </table>
                        </div>
  • |
{%if-driver.fullNationality%} 国籍 {{driver.fullNationality} {%endif%} {%if driver.age%} 年龄 {{driver.age} {%endif%} {%if driver.placeofbirth%} 天生的 {{driver.placeofbirth} {%endif%} {%if driver.lifes%} 生活 {{driver.lifes} {%endif%} 高度 5英尺11英寸 重量 175磅 最高比赛成绩 1(x64) 出生日期 07/01/1985 出生地 史蒂夫内奇,英国 团队 梅赛德斯 获胜 1. 讲台 3. 要点 2730 全科医生报名了 11 锦标赛 0 最高比赛成绩 1(x64) 最高网格位置 1.