无法触发图片点击事件

时间:2013-03-07 13:57:50

标签: jquery html

我有这样的代码:

我想在DIV元素中触发2图像的点击事件,但第二图像点击事件不起作用

<ul style="float: left; width: 898px; margin: 0px; overflow: hidden; position: relative; top: 0px; padding: 0px; left: 0px;" class="jcarousel-list jcarousel-list-horizontal" id="mycarousel">
            <li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-1 jcarousel-item-1-horizontal" style="float: left; list-style: none outside none; width: 52px;" jcarouselindex="1">
                <div style="position: relative">
                    <img width="40" height="40" style="cursor: pointer" title="Project 010" alt="image" class="5137aa052acf96352027d9a0|Project 010|Employee|5/1/2004|6/1/2011||||Descriptions**True|Skills**True|Client**true|Achievements**True|Memberships**False|Org Chart**False|Specialization**False|Get Ratings**False|" src="../Images/DefaultPhotoMale.png" id="img5137aa052acf96352027d9a0">
                    <img class="imgProjectDelete" style="position: absolute; display: none; top: 4px; right: 5px" src="../Images/RemoveButton.ico">
                </div>
            </li>
            <li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-2 jcarousel-item-2-horizontal" style="float: left; list-style: none outside none; width: 52px;" jcarouselindex="2">
                <div style="position: relative">
                    <img width="40" height="40" style="cursor: pointer" title="Project 009" alt="image" class="5137aa052acf96352027d995|Project 009|Employee|5/1/2002|5/1/2004||||Descriptions**True|Skills**True|Client**true|Achievements**True|Memberships**False|Org Chart**False|Specialization**False|Get Ratings**False|" src="../Images/DefaultPhotoMale.png" id="img5137aa052acf96352027d995">
                    <img class="imgProjectDelete" style="position: absolute; top: 4px; right: 5px; display: none;" src="../Images/RemoveButton.ico">
                </div>
            </li>
            <li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-3 jcarousel-item-3-horizontal" style="float: left; list-style: none outside none; width: 52px;" jcarouselindex="3">
                <div style="position: relative">
                    <img width="40" height="40" style="cursor: pointer" title="Project 008" alt="image" class="5137aa052acf96352027d987|Project 008|Employee|6/1/1994|5/1/2002||||Descriptions**True|Skills**True|Client**true|Achievements**False|Memberships**False|Org Chart**False|Specialization**False|Get Ratings**False|" src="../Images/DefaultPhotoMale.png" id="img5137aa052acf96352027d987">
                    <img class="imgProjectDelete" style="position: absolute; display: none; top: 4px; right: 5px" src="../Images/RemoveButton.ico">
                </div>
            </li>
        </ul>

我累的是: -

第一次图片点击事件是这样的,并且工作正常

 $("#mycarousel").find("img").live("click", function () {

    });

第二张图片点击事件是这样的,无法正常工作

 $("#mycarousel").find(".imgProjectDelete").live("click", function () {
        alert("You CLick on Delete");
    });

我想删除点击事件!无论我们使用其他元素作为第二张图片

2 个答案:

答案 0 :(得分:1)

好的,我将第二张图片更改为

并写下以下内容并且正在运作

$("#mycarousel").find("a").live("click", function () {

    });

答案 1 :(得分:0)

尝试

$(document).on("click","#mycarousel .imgProjectDelete",function(e){
//your code
});

或者如果您使用旧版本的jquery,请使用.delegate

$(document).delegate("#mycarousel .imgProjectDelete","click",function(e){
//your code
});