簡體   English   中英

如何打開頁面上帶有鏈接的javascript div選項卡

[英]How do I open javascript div tabs with a link on the page

我正在嘗試使用鏈接來打開使用div創建的特定標簽,然后使用javascript打開和關閉標簽。

這是選項卡,並且javascript在底部的script標記內:

<div class="span12 module_cont module_tabs">      
        <div class="shortcode_tabs">
            <div class="all_heads_cont">
                <div class="shortcode_tab_item_title it1 head1 active" data-open="body1">%%LNG_ProductDescription%%</div>
                <div class="shortcode_tab_item_title it2 head2" id="reviews" data-open="body2">%%LNG_JS_Reviews%%</div>
                <div class="shortcode_tab_item_title it3 head3" data-open="body3">%%LNG_JS_ProductVideos%%</div>
                <div class="shortcode_tab_item_title it4 head4" data-open="body4">%%LNG_JS_SimilarProducts%%</div>
            </div>
            <div class="all_body_cont">
                <div class="shortcode_tab_item_body body1 it1">
                    <div class="ip">
                        %%Panel.ProductDescription%%
                    </div>
                </div>
                <div class="shortcode_tab_item_body body2 it2">
                    <div class="ip">
                        %%Panel.ProductReviews%%                               
                    </div>
                </div>
                <div class="shortcode_tab_item_body body3 it3">
                    <div class="ip">
                        %%Panel.ProductVideos%%                                           
                    </div>
                </div>
                <div class="shortcode_tab_item_body body4 it4">
                    <div class="ip">
                        %%Panel.SimilarProductsByTag%%
                        %%Panel.ProductByCategory%%
                        %%Panel.ProductVendorsOtherProducts%%
                        %%Panel.SimilarProductsByCustomerViews%%               
                    </div>
                </div>
            </div>
        </div><!-- .shortcode_tabs -->                             
        <script type="text/javascript">
            jQuery('.shortcode_tabs').each(function(index) {                                    
                /* GET ALL HEADERS */
                var i = 1;
                jQuery('.shortcode_tab_item_title').each(function(index) {
                    jQuery(this).addClass('it'+i); jQuery(this).attr('whatopen', 'body'+i);
                    jQuery(this).addClass('head'+i);
                    jQuery(this).parents('.shortcode_tabs').find('.all_heads_cont').append(this);
                    i++;
                });
                /* GET ALL BODY */
                var i = 1;
                jQuery('.shortcode_tab_item_body').each(function(index) {
                    jQuery(this).addClass('body'+i);
                    jQuery(this).addClass('it'+i);
                    jQuery(this).parents('.shortcode_tabs').find('.all_body_cont').append(this);
                    i++;
                });
            });
            jQuery('.shortcode_tabs .all_body_cont div:first-child').addClass('active');
            jQuery('.shortcode_tabs .all_heads_cont div:first-child').addClass('active');

            jQuery('.shortcode_tab_item_title').live('click', function(){
                jQuery(this).parents('.shortcode_tabs').find('.shortcode_tab_item_body').removeClass('active');
                jQuery(this).parents('.shortcode_tabs').find('.shortcode_tab_item_title').removeClass('active');
                var whatopen = jQuery(this).attr('data-open');
                jQuery(this).parents('.shortcode_tabs').find('.'+whatopen).addClass('active');
                jQuery(this).addClass('active');
            });

            jQuery('reviews').live('click', function(){
                jQuery(this).parents('.shortcode_tabs').find('.shortcode_tab_item_body').removeClass('active');
                jQuery(this).parents('.shortcode_tabs').find('.shortcode_tab_item_title').removeClass('active');
                var whatopen = jQuery(this).attr('data-open');
                jQuery(this).parents('.shortcode_tabs').find('.'+whatopen).addClass('active');
                jQuery(this).addClass('active');
            });                                               
        </script>                                        
</div><!-- .module_cont -->

我想要做的就是在同一頁面上有一個鏈接,該鏈接可激活“評論”選項卡(id =“ reviews”),也稱為body2。

到目前為止,我的鏈接只有:

<a href="#reviews">Reviews</a>

救命。 我的腦袋疼...

您只需要設置鏈接,這樣就不會將用戶帶到新頁面,然后設置單擊事件以打開選項卡。 例:

HTML:

<a href='javascript:void(0);' id='reviewLink'>Review Tab</a>

JavaScript:

$('#reviewLink').click(function() {
    $('.shortcode_tab_item_body').css({display:'none'});
    $('.body2').css({display:'none'});
});

或這里的jsfiddle: http : //jsfiddle.net/tKLhn/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM