Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.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 通过Wordpress短代码的制表符_Javascript_Jquery_Wordpress - Fatal编程技术网

Javascript 通过Wordpress短代码的制表符

Javascript 通过Wordpress短代码的制表符,javascript,jquery,wordpress,Javascript,Jquery,Wordpress,我在将类添加到我当前在Wordpres中使用的一些jQuery选项卡时遇到问题。下面的代码创建了一个创建选项卡的短代码。我的问题是如何将类添加到正在显示的选项卡“活动”选项卡中。我希望能够将这个类添加到显示的选项卡中,这样我就可以使用CSS对其进行样式设置。以下是我当前使用的代码,它可以查找,但没有向活动选项卡添加任何类: add_shortcode( 'tabgroup', 'jqtools_tab_group' ); function jqtools_tab_group( $atts, $c

我在将类添加到我当前在Wordpres中使用的一些jQuery选项卡时遇到问题。下面的代码创建了一个创建选项卡的短代码。我的问题是如何将类添加到正在显示的选项卡“活动”选项卡中。我希望能够将这个类添加到显示的选项卡中,这样我就可以使用CSS对其进行样式设置。以下是我当前使用的代码,它可以查找,但没有向活动选项卡添加任何类:

add_shortcode( 'tabgroup', 'jqtools_tab_group' );
function jqtools_tab_group( $atts, $content ){
$GLOBALS['tab_count'] = 0;

do_shortcode( $content );

if( is_array( $GLOBALS['tabs'] ) ){
foreach( $GLOBALS['tabs'] as $tab ){
$tabs[] = '<li><a class="" href="#">'.$tab['title'].'</a></li>';
$panes[] = '<div class="pane"><h3>'.$tab['title'].'</h3>'.$tab['content'].'</div>';
}
$return = "\n".'<!-- the tabs --><ul class="tabs">'.implode( "\n", $tabs ).'</ul>'."\n".'<!-- tab "panes" --><div class="panes">'.implode( "\n", $panes ).'</div>'."\n";
}
return $return;
}

add_shortcode( 'tab', 'jqtools_tab' );
function jqtools_tab( $atts, $content ){
extract(shortcode_atts(array(
'title' => 'Tab %d'
), $atts));

$x = $GLOBALS['tab_count'];
$GLOBALS['tabs'][$x] = array( 'title' => sprintf( $title, $GLOBALS['tab_count'] ), 'content' =>      $content );

$GLOBALS['tab_count']++;
}

谢谢。

如果使用jquery/javascript添加类会更好

如果确定页面加载时哪个选项卡处于活动状态,则可以通过jquery动态添加活动类

$(document).ready(function() {
// That is if the first tab is the default active tab.
// Assuming the li tag is what you want to apply the 'active' class on
$('ul.tabs li:first').addClass('active');

// Manipulate Class on click event.
// Assuming the li tag is what you want to apply the 'active' class on


$('ul.li a').click(function() {
// Remove any 'active' class previously added.
$(this).parent().siblings().removeClass('active');

// Add 'active' class to the selected tab.
$(this).parent().addClass('active');

});
});

希望这有帮助

这成功了!对你的代码做了一些小的调整,但我不认为没有它我就做不到,非常感谢!干杯