使整个博客发布预览可点击

时间:2012-05-28 10:39:23

标签: javascript blogger

在我的网站www.beatmushroom.com上运行在博客平台上我在主页上有我的帖子的小预览。要获得完整的帖子,您必须单击标题。我希望能够点击帖子预览中的任何地方(缩略图和文本),它会带我到帖子。我想可能有一些方法可以用javascript做到这一点。

在主页上的源代码中,帖子由以下内容组成:

    <div class="date-outer">


    <div class="date-posts">

    <div class='post-outer'>
    <div class='post hentry'>
    <a name='366770510419642006'></a>
    <h2>
    <a href='http://www.beatmushroom.com/2012/05/logic-we-get-high.html'>Logic - We Get High</a>
    </h2>
    <div class='post-header'>
    <div class='post-header-line-1'></div>
    </div>
    <div class='post-body entry-content' id='post-body-366770510419642006'>
    <span class="tags">Rap</span><br>
    <img border="0" src="http://3.bp.blogspot.com/-qkVnjpTBMjY/T78PmQDUAvI/AAAAAAAAAKA/cUEMjJQ3w5s/s1600/logic.jpg">Here is a new one check it out logic has some good chilled tracks this has got a pretty old school feel to it. I am adding the blog to technorati. Technorati code: 886BP6K6GWA7<br>
    <div style='clear: both;'></div>
    </div>
    <div class='jump-link'>
    <a href='http://www.beatmushroom.com/2012/05/logic-we-get-high.html#more' title='Logic - We Get High'>&#9834; Listen Here &#187;</a>
    </div>
    <div class='post-footer'>
    <div class='post-footer-line post-footer-line-1'><span class='post-author vcard'>
    </span>
    <span class='post-timestamp'>
    </span>
    <span class='post-comment-link'>
    </span>
    <span class='post-icons'>
    <span class='item-control blog-admin pid-1598740620'>
    <a href='http://www.blogger.com/post-edit.g?blogID=4929692547831239344&postID=366770510419642006&from=pencil' title='Edit Post'>
    <img alt='' class='icon-action' height='18' src='http://img2.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/>
    </a>
    </span>
    </span>
    <div class='post-share-buttons goog-inline-block'>
    </div>
    </div>
    <div class='post-footer-line post-footer-line-2'><span class='post-labels'>
    </span>
    </div>
    <div class='post-footer-line post-footer-line-3'>
    <span class='post-location'>
    </span>
    </div>
    </div>
    </div>
    </div>

有没有办法从这里获取链接:

<h2>
<a href='http://www.beatmushroom.com/2012/05/logic-we-get-high.html'>Logic - We Get High</a>
</h2>

然后创建元素:

    <div class="date-outer">   

链接到那个?

因为帖子的其余部分位于该元素内部,所以它会使帖子预览成为一个链接。然后他们必须点击背景,但我可能会使z-index工作?

2 个答案:

答案 0 :(得分:0)

假设每个date-outer元素包含一个包含单个锚点的2级标题:

$('.date-outer').each(function () {   
    $(this).click(function () {
        window.location = $('h2 a', this).attr('href');        
    });
});​

http://jsfiddle.net/WHd5d/1/

答案 1 :(得分:0)

如果您希望能够点击帖子中的任何内容并让它执行您想要的操作,请考虑使用*选择器

$('previewpost *').click(function() {
       doWhatever(); 
});