通咿APPEND生成的DIV触发不了CLICK时间,但是直接人手写在页面上的DIV却可以。请问有人知道是怎么回事吗?
<div id="div_room_container" class="lease_room_container">
<div id="handle_by_Manual" class="room">azaz</div> //人手写在页面上,能触发click
<div id="A101" class="room">A101</div> //通咿ajax生成,无法触发click事件
<div id="A102" class="room">A102</div> //通咿ajax生成,无法触发click事件
<div id="A103" class="room">A103</div> //通咿ajax生成,无法触发click事件
<div id="A104" class="room">A104</div> //通咿ajax生成,无法触发click事件
</div>
$(document).ready(function () {
$(".room").click(function () {
alert('OK');
//alert($(this).html());
});
$.ajax({
type: 'get',
url: "Ajax_Service/LeaseService.aspx",
data: 'request_type=getrooms&' + 'roomid=' + '' + '&district=' + 'A' + '&action=' + 'D',
//data: { roomid: 'aaa', district: 'A', action: 'D' },
success: function (data) {
//$('#div_room_container').empty();
var myarray = $.parseJSON(data);
$.each(myarray, function (i, item) {
$('#div_room_container').append(
"<div class='room' id='" + item.roomid + "'>" + item.room_cname + "</div>"
);
})
},
error: function () { alert('ajax failed'); }
});
});