weixin_33725807 2012-05-03 23:42 采纳率: 0%
浏览 29

Ajax的Jquery .Hover问题

Hey guys I have this code

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 Id cut-imageplacer is display:none, so what I want is when someone hovers the controller-image div, the cut-imageplacer to show and hide of course when not on. I use this code

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

But it doesnt work... Any idea what I am doing wrong? Or point me to correct direction?

  • 写回答

1条回答 默认 最新

  • weixin_33720956 2012-05-03 23:54
    关注

    It look like you are trying to attach events to elements that are being dynamically created. You need to use Live() or On() to attach events to these elements after they are created. Look at This and This to see how to use those.

    like:

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

报告相同问题?

悬赏问题

  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)