duanquanzhi5560 2012-08-19 04:03
浏览 18
已采纳

从另一个页面计算<LI>元素

I have two pages, page A and page B. Page A will hold an unknown number of unordered list elements. I wont have any control on how many list elements there are.

On Page B, I'd like to use PHP to grab the number of li from Page A and display that number. The idea is Page A will hold Wordpress post links that a user has favorited, while Page B will display that amount of favorites.

Any help would be wonderful. Thanks

  • 写回答

1条回答 默认 最新

  • doucan8049 2012-08-19 04:10
    关注

    Parse html from another page using PHP Simple HTML DOM Parser. Download it and include to your script:

    include('simple_html_dom.php');
    $html = file_get_html('http://example.com/yourpage.php');
    $licount = count($html->find('li')); // Here it is
    

    Okay. Looks like OP don't need to use serverside code. Use javascript for this (don't forget to include jQuery):

    $(document).ready(function(){
        $.get("/favorites", function(data){
            $("#favorites").html($("li", $(data)).length)
        })
    })
    

    This will replace content of element #favorites with number of lis in /favorites file

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?