我使用以下代码,我希望能够从与单击它时<li>
关联的(帖子 ID)获取 ID 属性<a>
,但我无法弄清楚如何做到这一点。有人可以帮助我吗?
<li id="custom_latest_news-5" class="widget custom_widget_latest_news">
<div class="widget-title">
<a href="http://test.dynedrewett.com/news-and-events/">Latest news</a>
</div>
<div class="widget-content">
<ul class="link-list ajax-links">
<li id="post-5521"><a href="http://mydomain.com/uk-news/last-call-for-self-assessment-tax-forms/">Last call for self-assessment tax forms</a></li>
<li id="post-5523"><a href="http://mydomain.com/uk-news/young-drivers-gambling-on-no-insurance/">Young drivers gambling on no insurance</a></li>
<li id="post-5520"><a href="http://mydomain.com/uk-news/tenants-forced-to-abandon-pets/">Tenants forced to abandon pets</a></li>
</ul>
</div>
</li>
这是我目前拥有的 JS -
/**
* Intercept a click for page refresh and run the page refresh JS
*/
$(function(){
$('.ajax-links').delegate('li a', 'click', function(e){
/** Prevent the click from doing anything */
e.preventDefault();
/** Get the post ID */
var post_id = '???';
});
});
谢谢。