[英]Can't request data from div after ajax call. How do I fix this?
This example works well and the same I use on my project, but the data I use, in this case the div with the data-name
attr is loaded by ajax and it looks like it doesn't work. 这个示例运行良好,并且与我在项目中使用的示例相同,但是我使用的数据(在这种情况下, data-name
attr的div是由ajax加载的,看起来好像不起作用)。 In the console, firefox output this after the click
: 在控制台中,在click
之后,firefox输出以下内容:
getPreventDefault() sollte nicht mehr verwendet werden. getPreventDefault()解决方案。 Verwenden Sie stattdessen defaultPrevented.jquery.min... Verwenden Sie stattdessen defaultPrevented.jquery.min ...
http://jsfiddle.net/n495c/14/ http://jsfiddle.net/n495c/14/
js js
$(document).ready(function() {
$("#content div").click(function() {
var title = $(this).data("name");
$("#content div").text(title);
});
});
html html
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="content">
<div data-name="Neu"></div>
</div>
css 的CSS
#content {
width: 100%;
height: 100%;
}
#content div {
width: 50px;
height: 50px;
background: red;
color: white;
}
Delegated event handler : 委托事件处理程序:
$(document).ready(function() {
$(document).on('click', '#content div', function() {
var title = $(this).data("name");
$("#content div").text(title);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.