日期:2014-05-16  浏览次数:20510 次

通过ajax获取的数据,如何让其它js能执行?
通过ajax读取数据
 $(document).ready(function () {
//ajax读取数据并设置把相应的UL中的LI 某个ID上,

$.ajax({
            type: "get",
            dataType: "html",
            url: '/Ashx/act.ashx',
            data: sql,
 success: function (data) {
                $("#" + showul).html(data)
            },
});
});


================
需要执行的JS代码
$('li.caption').hover(function () {
            $(".cover", this).stop().animate({ top: '0px' }, { queue: false, duration: 160 });
        }, function () {
            $(".cover", this).stop().animate({ top: '-307px' }, { queue: false, duration: 160 });
        });

如果把数据直接写在页面上,上面这JS代码可以执行,但如果数据是通过ajax读取后再附加到页面上,而这块JS代码起不到作用,请教这要如何解决。谢谢。

------解决方案--------------------
引用:

$(document).on("hover","li.caption",function () {
            $(".cover", this).stop().animate({ top: '0px' }, { queue: false, duration: 160 });
        }, function () {
            $(".cover", this).stop().animate({ top: '-307px' }, { queue: false, duration: 160 });
        });

hover 改成 mouseover
------解决方案--------------------
jquery 的ajax把
<script scr='x'></script>封装好了。


// Install script dataType
jQuery.ajaxSetup({
accepts: {
script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
},
contents: {
script: /(?:java
------解决方案--------------------
ecma)script/
},
converters: {
"text script": func