日期:2014-05-16 浏览次数:20349 次
<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'); }
})