Home > Backend Development > PHP Tutorial > jQuery获取URL最后的ID

jQuery获取URL最后的ID

WBOY
Release: 2016-06-06 20:51:08
Original
1280 people have browsed it

JQ获取.post-PrevNext第一个/第二个P的URL最后的ID(215、283),并且定义对应的php函数等于这个ID,$prev_post_id与$next_post_id

<div class="post-PrevNext">
        <p> 上一篇: <a href="http://3e21321.com/?p=215" rel="prev">账上</a> </p>
        <p> 下一篇: <a href="http://3e21321.com/?p=283" rel="next">李四</a> </p>
</div>
<div>
        <?php echo $prev_post_id;?><?php echo $next_post_id;?>
</div>
Copy after login
Copy after login

回复内容:

JQ获取.post-PrevNext第一个/第二个P的URL最后的ID(215、283),并且定义对应的php函数等于这个ID,$prev_post_id与$next_post_id

<div class="post-PrevNext">
        <p> 上一篇: <a href="http://3e21321.com/?p=215" rel="prev">账上</a> </p>
        <p> 下一篇: <a href="http://3e21321.com/?p=283" rel="next">李四</a> </p>
</div>
<div>
        <?php echo $prev_post_id;?><?php echo $next_post_id;?>
</div>
Copy after login
Copy after login

var $prev_post_id = $('.post-PrevNext > p > a').eq(0).attr('href').replace(/.*(\d+)$/,"$1");
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template