无法在jQuery中处理从ajax请求插入的数据 [英] Can't Manipulate data inserted from an ajax request in jQuery

查看:66
本文介绍了无法在jQuery中处理从ajax请求插入的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用服务器并转动数据后,它返回到表中。我使用jQuery的.html()语法将其插入到页面中。之后,数据出现在页面中,但我无法使用jQuery操作它。

After calling the server and turning the data it returns into a table. I insert it into the page using jQuery's .html() syntax. After that the data appears in the page but I can't manipulate it using jQuery.

继承人代码:

<html>
<head>
    <title>testJavaScript</title>

    <script type="text/javascript" src="jquery-1.4.2.js"></script>

    <script type="text/javascript">

    function makeTable(data) {

        var htmlOut = "<table id=\"AjaxTable\">";

        for (x in data) {
            htmlOut += "<tr>";
            for (y in data[x]) {
                htmlOut += "<td>"+data[x][y]+"</td>";
            }
            htmlOut += "</tr>";
        }

        htmlOut += "</table>";

        return htmlOut;
    }

    function getValue() {
        return $("#MyText").val()
    }

    $(document).ready(function () {

        $("img").hover(function () { //This dosent work on the data returned from the server
            $(this).hide(1000)
            //$(this).css({'background-color': '#357EC7', 'border': '2px solid #2B60DE'});
        })

        $("#populateDrop").click(function () {
            $.getJSON('http://127.0.0.1:5000/ajaxTest/json?num='+ getValue() +'&callback=?', function(data) {
                $(".result").html(makeTable(data.data));
            })

        })
    })
    </script>
</head>

<body>
    <img src="http://www.sharejs.com/code/windows/light-window/gallery/1-nature.jpg" width="50" height="50" /></br>
    <form>
    <input id="MyText" type="text" value="15" />
    </form>
    <a href="#" id="populateDrop">Populate!</a></br>
    <div class="result"></div>
</body>

推荐答案

您需要使用 live 代替动态数据:

You need to use live instead for dynamic data:

$("img").live('hover', function () {
 $(this).hide(1000);
});

更多信息:

  • http://api.jquery.com/live/

这篇关于无法在jQuery中处理从ajax请求插入的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆