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

jQuery获取URL最后的ID

WBOY
WBOYOriginal
2016-06-06 20:51:081245browse

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>

回复内容:

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>

var $prev_post_id = $('.post-PrevNext > p > a').eq(0).attr('href').replace(/.*(\d+)$/,"$1");
Statement:
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