Jquery Tablesorter在Wordpress插件中不工作
我想在我的wordpress插件中使用tablesorter 这就是我的桌子的样子Jquery Tablesorter在Wordpress插件中不工作,jquery,wordpress,tablesorter,Jquery,Wordpress,Tablesorter,我想在我的wordpress插件中使用tablesorter 这就是我的桌子的样子 <table class="table table-condensed table-striped" style="font-size:80%;" id="table_id"> <thead align="left"> <tr> <th>col1</th> <th>col
<table class="table table-condensed table-striped" style="font-size:80%;" id="table_id">
<thead align="left">
<tr>
<th>col1</th>
<th>col2</th>
<th style="min-width:6em;">col3</th>
<th style="min-width:4em";>col4</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
在我使用的javascript文件中
wp_enqueue_script('tablesorter', plugin_dir_url( __FILE__ ) . 'js/jquery.tablesorter.js', array('jquery172'));
$("#table_id").tablesorter();
我将文件jquery.tablesorter.js复制到我的js目录中。但什么也没发生。你知道哪里出了问题吗?你有没有试过wordpress的这个特殊的助手功能来让它工作
也许这将帮助您更好地解决问题。还可以在答案中添加内容
/**
* Make all tables with the specified identifier sortable using the jQuery Tablesorter
plugin.
*
* @uses wp_enqueue_script() To enqueue the jQuery Tablesorter script.
*
* @param string $identifier jQuery selector (.sortable, #element_id, table, etc.)
* @param array $args Default is empty string. Array of arguments to pass to
$.tablesorter()
* @return void
*/
function make_table_sortable($identifier, $args = '') {
global $sortable_tables;
if ( in_array($identifier, (array)$sortable_tables) )
return;
wp_enqueue_script('jquery-tablesorter');
$sortable_tables[] = array(
'identifier' => $identifier,
'args' => $args
);
add_action('admin_print_footer_scripts', '_make_table_sortable');
}
function _make_table_sortable() {
global $sortable_tables;
if ( count( (array)$sortable_tables ) <= 0 )
return;
?>
<script type="text/javascript">
<?php
foreach ($sortable_tables as $sortable_table) {
if ( !is_array($sortable_table['args']) ) {
$arguments = '';
} else {
$arguments = '{';
$args_count = sizeof($sortable_table['args']);
$i = 0;
foreach ($sortable_table['args'] as $k => $v) {
$arguments .= $k . ': ' . $v;
if (++$i != $args_count) $arguments .= ', ';
}
$arguments .= '}';
}
?>
$('<?php echo esc_js($sortable_table['identifier']); ?>').tablesorter(<?php
echo esc_js($arguments); ?>);
<?php } ?>
</script>
<?php
}
// Sort tables with class 'sortable', first and second columns in ascending
// order with first taking precedence.
make_table_sortable('.sortable', array('sortList' => '[[0,0], [1,0]]'));
// Sort table with ID 'sortable', first column in ascending order. Turn debugging on.
make_table_sortable('#sortable', array('sortList' => '[[1,0]]', 'debug' => 'true'));