dp709369831 2016-02-22 15:28
浏览 53
已采纳

在php中为特定的get请求执行javascript

Suppose my domain name is www.example.com and I have a category, which contains many items. Example, Travel, Books, Education. Now, if I click on Travel the get request is www.example.com/category/travel-areas. Now, I want to execute a script when particularly that Travel is clicked from category, like <script>alert("hi")</script> it will be executed when I open www.example.com/category/travel-areas This is my category.php file :-

<div class="content">

<?php tie_breadcrumbs() ?>

<?php
    $category_id = get_query_var('cat') ;
    $tie_cats_options = get_option( 'tie_cats_options' );

    if( !empty( $tie_cats_options[ $category_id ] ) )
        $cat_options = $tie_cats_options[ $category_id ];
?>

    <div class="page-head">

        <h1 class="page-title">
            <?php echo single_cat_title( '', false ) ?>
        </h1>

        <?php if( tie_get_option( 'category_rss' ) ): ?>
        <a class="rss-cat-icon ttip" title="<?php _eti( 'Feed Subscription' ); ?>" href="<?php echo get_category_feed_link($category_id) ?>"><i class="fa fa-rss"></i></a>
        <?php endif; ?>

        <div class="stripe-line"></div>

        <?php
        if( tie_get_option( 'category_desc' ) ):    
            $category_description = category_description();
            if ( ! empty( $category_description ) )
            echo '<div class="clear"></div><div class="archive-meta">' . $category_description . '</div>';
        endif;
        ?>
    </div>

    <?php get_template_part( 'framework/parts/slider-category' ); ?>

    <?php $loop_layout = ( !empty( $cat_options[ 'category_layout' ] ) ? $cat_options[ 'category_layout' ] :  tie_get_option( 'category_layout' ) );    ?>

    <?php get_template_part( 'loop' );  ?>

    <?php if ($wp_query->max_num_pages > 1) tie_pagenavi(); ?>

</div> <!-- .content -->
  • 写回答

1条回答 默认 最新

  • douzuo0711 2016-02-22 16:22
    关注

    In your code there is no part, where exactly link is displayed. But i can suggest that you have list of links to different areas. For example :

    <a href="#" class="travel-area" data-id="1"> Area title</a>
    

    So i added some example to Jsfiddle. As you can see, some part of JS code will be executed only when be passed if expression. You can change that expression, so add some additional check.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看