[英]Can't Manipulate data inserted from an ajax request in 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.
我使用jQuery的.html()语法将其插入页面。 After that the data appears in the page but I can't manipulate it using jQuery.
之后,数据将显示在页面中,但我无法使用jQuery进行操作。
heres the code: 这是代码:
<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>
You need to use live
instead for dynamic data: 您需要使用
live
代替动态数据:
$("img").live('hover', function () {
$(this).hide(1000);
});
More Info: 更多信息:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.