

Mình muốn thêm lớp hoạt động trong phần tử đầu tiên của li, đây là mã amp.. nhưng hình như jquery bằng cách thần kì nào đó mà nó không hoạt động.
Help me please!
Help me please!
PHP:
Function custom_table_of_contents ($content) {
Global $tableOfContents;
Global $checkvalue;
$tableOfContents = '';
$tableOfContents = "<ul class='toc-item-list'>";
$checkvalue = 0;
$index = 1;
$indexes = [2 => 1, 3 => 0, 4 => 0, 5 => 0, 6 => 0] ;
$content = preg_replace_callback ('#< (h[1-6] ) (. *) > (. *) </\1>#si', function ($matches) use (&$index, &$tableOfContents, &$indexes, &$checkvalue) {
$tag = $matches[1] ;
$title = strip_tags ($matches[3] ) ;
$hasId = preg_match ('/id= ([ "\'] ) (. *) \1[\s>] /si', $matches[2], $matchedIds) ;
$id = $hasId? $matchedIds[2]: Sanitize_title ($title) ;
Foreach (range (2, $tag[1] ) as $i) {
If ($i == $tag[1] ) {
$indexes[$i] += 1;
}
}
$title =" $title ";
If ($checkvalue<$tag)
{
$tableOfContents. = '<ul>';
} else if ($checkvalue==$tag) {
} else if ($checkvalue>$tag) {
$tableOfContents. ='</ul>';
}
$checkvalue=$tag;
$tableOfContents .= "<li class='$id active'><a href='#$id'>$title</a></li>";
If ($hasId) {
Return $matches[0] ;
}
Return sprintf ('<%s%s id=" %s">%s</%s>', $tag, $matches[2], $id, $matches[3], $tag) ;
}, $content) ;
$tableOfContents. = '</ul>';
Echo $tableOfContents;
Return $content;
}
Last edited by a moderator: