Hỏi đáp Thêm active class vào phần tử con đầu tiên PHP

Discussion in 'Hỏi & Đáp' started by Quachni, Apr 21, 2021.

  1. Quachni Developer

    Messages:
    18
    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!

    Function custom_table_of_contents ($content) {

    Global 
    $tableOfContents;

    Global 
    $checkvalue;

    $tableOfContents '';

    $tableOfContents "<ul class='toc-item-list'>";

    $checkvalue 0;

    $index 1;

    $indexes = [=> 1=> 0=> 0=> 0=> 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: Apr 21, 2021
  2. Ghost

    Messages:
    12
    Bạn có thể sử dụng hàm. AddClass () của Jquery với cú pháp như sau:

    Code:
    $("li").first().addClass("active");
     
Tags:
Trả lời qua Facebook
Loading...