如何将我在页面上的多个j查询脚本合并为一个?

时间:2015-08-25 21:19:01

标签: javascript php jquery wordpress performance

我的页面中有八个单独的脚本,可以将slideToggle()行为添加到八个不同的元素中。是否有将它合并为一个单独的脚本,以免影响页面加载时间?

<div id="proficiencies_holder">
    <div id="proficiencies_menu">
        [insert_php] 
            $args = array('category_name'=>'competencies-and-domains','posts_per_page'=> -1);
            $query = new WP_Query($args);
            $i = 0;
            while($query->have_posts()):
                $i+=1;
                $query->the_post();
                $div_image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'full');
                echo '<div class="prof_menu_item_holder">';
                echo '<div id="prof_button'.$i.'"class="prof_menu_item custom-parallax"style="background-image: linear-gradient(rgba(0,0,0,.3),rgba(0,0,0,.3)),url('.$div_image[0].')">';
                echo get_the_title();
                echo '</div>';
                echo '<div id="par_tab'.$i.'">';
                echo get_the_content();
                echo '</div>';
                echo '</div>';
                echo '<script>$(document).ready(function(){$("#prof_button'.$i.'").click(function(){$("#par_tab'.$i.'").slideToggle();});});</script>';
            endwhile;
        [/insert_php]
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

为什么不使用课程?例如:prof_button和par_tab

DateTime possibleDateTime;
if (!DateTime.TryParse(context.Request.QueryString["solutionDate"], out possibleDateTime))
{
    //handle the situation where the parse fails
}

//if you get here you know there's a valid datetime in possibleDateTime

演示:How can I read a file (data stream, variable) line-by-line (and/or field-by-field)?