首页 新闻 搜索 专区 学院

写在append里的onclick事件在运行后点击没有反映

0
[已解决问题] 解决于 2015-12-15 16:47

<script type="text/javascript">
    $(document).ready(function () {
        var kv_num = 0;
        function nextKv() {
            alert("下一个");
            $(".control").attr("style", "pointer-events:none");
            kv_num++;
            if (kv_num == 4) { kv_num = 0; }
            $(".kv_pic").animate({ left: -1000 * kv_num }, { easing: 'easeInOutQuad', duration: 500, complete: function () {
                $(".control").attr("style", "pointer-events:auto");
            }
            });
            $(".kv_word>ul").stop().animate({ left: -340 * kv_num }, { easing: 'easeInOutQuad', duration: 800, complete: function () { } });
            $(".kv_dot ul li").removeClass("action").eq(kv_num).addClass("action");
        }
        function prevKv() {
            alert("上一个");
            $(".control").attr("style", "pointer-events:none");
            kv_num--;
            if (kv_num == -1) { kv_num = 3; }
            $(".kv_pic").animate({ left: -1000 * kv_num }, { easing: 'easeInOutQuad', duration: 500, complete: function () {

                $(".control").attr("style", "pointer-events:auto");
            }
            });
            $(".kv_word>ul").stop().animate({ left: -340 * kv_num }, { easing: 'easeInOutQuad', duration: 800, complete: function () { } });
        }
    });

  $("#kv").append("</div><div class='control'><div class='prev'><img src='../../image/icons_move_left.jpg' onclick='prevKv();'/></div><div class='next'><img id='nextKv' src='../../image/icons_move_right.jpg' onclick='nextKv();'/></div></div>");
</script>

玩世不恭的雷寅的主页 玩世不恭的雷寅 | 初学一级 | 园豆:38
提问于:2015-12-15 14:56
< >
分享
最佳答案
0
//onclick拿掉
$("#kv").append("</div><div class='control'><div class='prev'><img src='../../image/icons_move_left.jpg' /></div><div class='next'><img id='nextKv' src='../../image/icons_move_right.jpg' /></div></div>");

//$(document).ready加上這兩個
$(document).on('click', '.prev', function () {
    prevKv();
})
$(document).on('click', '.next', function () {
    nextKv();
})

試試

奖励园豆:5
RosonJ | 老鸟四级 |园豆:3763 | 2015-12-15 16:33

非常完美解决啦,感谢大神的专业回答!谢谢!

玩世不恭的雷寅 | 园豆:38 (初学一级) | 2015-12-15 16:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册