【问题标题】:adding a new image after a click单击后添加新图像
【发布时间】:2012-11-04 16:02:28
【问题描述】:

当我单击 z pass 按钮时,我正在尝试添加新图像 我的这部分代码不起作用

http://jsfiddle.net/UjJEJ/24/

$(".ctaSpecialOne").click(function(){                    
                         alert("clicked");  

$(this).parent().unbind("mouseenter").children("img").attr("src", "http://www.onlinegrocerystore.co.uk/images/goodfood.jpg");                


                 });

【问题讨论】:

    标签: jquery-ui jquery jquery-plugins jqgrid


    【解决方案1】:

    您需要遍历兄弟a,因为那是您的图像所在的位置

    $(this).parent().unbind("mouseenter").siblings('a').children("img").attr("src", "http://www.onlinegrocerystore.co.uk/images/goodfood.jpg");       
    

    http://jsfiddle.net/WAvVw/

    编辑

    你需要遍历获取你绑定的悬停元素

    $(this)
       .closest('.specialHoverOne') // get element you bound hover to
       .unbind("mouseenter") // unbind event
       .end() // start over at this
       .parent()  // get parent
       .siblings('a') //find a sibling
       .children("img") // get children img
       .attr("src", "http://www.onlinegrocerystore.co.uk/images/goodfood.jpg"); // change src  
    

    http://jsfiddle.net/mwPeb/

    我确定有更好的遍历方式,但我现在时间不多了

    【讨论】:

    • 感谢您的回复,但是一旦添加了图像,zpass按钮就不应该出现...如何实现它
    • jsfiddle.net/WAvVw/1 通过背景颜色也不起作用 $(this).css("background-color","re​​d");
    • 不是添加新图像,而是可以更改同一图像的不透明度,以便我可以提高浏览器速度
    猜你喜欢
    • 2018-08-26
    • 1970-01-01
    • 2015-09-19
    • 2012-03-30
    • 1970-01-01
    • 2021-11-28
    • 2020-04-16
    • 2020-12-16
    • 1970-01-01
    相关资源
    最近更新 更多