1

嘿伙计们我有这个代码

cuts_html = '';
for( i = 0; i < attachments.length; i++ ) {
    fburl3 = site_url + '/haircut-detail/?img_id=' + attachments[i].ID + '&uid=' + attachments[i].post_author;
    if( isNaN(attachments[i].view_count) ) attachments[i].view_count = 0;

    cuts_html += '<div id="controller-image" class="cut-image">';



    cuts_html += '<div id="cut-imageplacer">';




    cuts_html +=    '<div class="cut-image-info">' +
                        'By <a href="' + user_profile_url + 
                        '&user_id=' + attachments[i].post_author + '">' +
                        attachments[i].author_name + '</a>' +
                        '</div>';

    cuts_html +=    '<div class="commentbox-1">' +
                        '<img src="https://d2xcq4qphg1ge9.cloudfront.net/assets/17276/435546/original_views.png">&nbsp;&nbsp;' +
                        attachments[i].view_count + 
                        '&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://d2xcq4qphg1ge9.cloudfront.net/assets/17276/435545/original_talk-bubble.png">&nbsp;&nbsp;' +
                        '<fb:comments-count href="' + fburl3 + '"></fb:comments-count>' +
                        '</div></div>';

    cuts_html +=    '<a class="cut-image-a" ' +
                        'href="' + image_detail_url + 
                        '?uid=' + attachments[i].post_author + 
                        '&img_id=' + attachments[i].ID + '">' +
                        attachments[i].attachment_image_html + '</a>';


    cuts_html += '</div>';
}

div Idcut-imageplacerdisplay:none,所以我想要的是当有人悬停controller-imagediv 时,cut-imageplacer当然可以在不打开时显示和隐藏。我使用此代码

<script type="text/javascript">$(document).ready(function(){    $('.cut-image').hover(
    function(){     $('#cut-imageplacer').show();
}, function () {        $('#cut-imageplacer').hide();    });  }); </script>

但它不起作用......知道我做错了什么吗?或者指出我正确的方向?

4

1 回答 1

2

看起来您正在尝试将事件附加到动态创建的元素。创建这些元素后,您需要使用Live()或将事件附加到这些元素。On()查看ThisThis以了解如何使用它们。

像:

<script type="text/javascript">
      $(document).ready(function(){    
       $('.cut-image').live("hover",
          function(){     
              $('#cut-imageplacer').show();
          }, function () {        
              $('#cut-imageplacer').hide();    
           });  
       }); </script>
于 2012-05-03T23:54:40.130 回答