我有一个复选框列表,每个复选框都有相同的class。如何使用jquery来检测复选框的click或change事件?我需要这样做,以便加载数据并显示单击复选框的模式。
<div class="widget widget-4" style="float:left;padding:10px;">
<div class="widget-head">
<h4 class="heading">Alert to Delivery Methods</h4>
</div>
<div style="clear:both;"></div>
<div class="widget-body">
<table class="table table-bordered table-striped">
<tbody>
<?php
foreach($model->model_alert_2_delivery_methods as $key => $alert) { ?>
<tr>
<td>
<?php
echo $form->checkBox($alert, 'name', array(
'name' => 'AlertDeliveryMethods[' . ($alert->id) . ']',
'class' => 'modal__package_create_popup_alert_delivery_methods',)
);
?>
</td>
<td>
<?php
echo $alert->name;
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<script>
$(document).ready(function() {
$('.modal_package_create_alert_delivery_methods').change(
function() {
console.log('evrika');
}
);
}
);
</script>发布于 2014-01-31 09:21:33
你应该使用.on()
$(document).on('change','.modal_package_create_alert_delivery_methods',function(){
console.log('evrika');
})发布于 2014-01-31 09:21:06
使用J查询的函数。
$('.modal_package_create_alert_delivery_methods').on('change',
function() {
console.log('evrika');
}
);如果使用的jquery版本少于1.7,则使用live()而不是on()
发布于 2014-01-31 09:21:45
试试这段代码
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$(".mm").on("change",function(){
alert(this.value);
});
});
</script>
</head>
<body>
<input type='checkbox' class='mm' value='1'>
<input type='checkbox' class='mm' value='1'>
<input type='checkbox' class='mm' value='1'>
</body>
</html>https://stackoverflow.com/questions/21476271
复制相似问题