麻烦在以下代码中在.data("blog-title")悬停时获取此值:.avatar

<a target="_blank" href="http://somwhere.com/"  class="frame">
<img alt="" class="avatar" src="http://something.com/pong.png/>
        </a>
        <script type="text/javascript">
            some script stuff
        </script>

            <div class="note">
                        <a target="_blank" class="preview" href="http://something.com/blogpost/bar"><img src="http://http://something.com/some.gif" /></a>
                <a href="#" data-blog-title="fooname" class="block">foobar</a>
            </div>


尝试过各种父母,发现等。只是无法解决。

最佳答案

尝试这个:-

假设您有多个这样的部分,则可以尝试这种方式

$('.avatar').hover(function(){
var value = $(this)
          .closest('.frame') // Get to the parent .frame
          .siblings('.note') // look for its sibling .note
          .find('.block') //find the anchor with class.block
          .data('blog-title'); //get the value. If this attribute value is being changed dynamically after the load then you need to use .attr('data-blog-title')

});


否则就做

 $('.block').data('blog-title');


http://jsfiddle.net/kNntX/

记得在这里关闭引号

<img alt="" class="avatar" src="http://something.com/pong.png/">
                                                              ^----------

关于jquery - 使用JQuery获得此值的麻烦,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16930018/

10-10 15:51