Javascript 为什么我的复选框和双击功能没有响应?
我有这段代码,在运行中创建一个带有复选框的表,并在一分钟后刷新。复选框和双击功能不起作用,我不知道为什么。请帮忙Javascript 为什么我的复选框和双击功能没有响应?,javascript,php,jquery,mysql,Javascript,Php,Jquery,Mysql,我有这段代码,在运行中创建一个带有复选框的表,并在一分钟后刷新。复选框和双击功能不起作用,我不知道为什么。请帮忙 <script type='text/javascript'> function vehicle() { $('#Vehicles').html( <?php $username =$_SESSION['user_name']; $sql = "select * from gps_product where g
<script type='text/javascript'>
function vehicle() {
$('#Vehicles').html(
<?php
$username =$_SESSION['user_name'];
$sql = "select * from gps_product where gp_userid ='$username'";
$db = new DbClass($sql);
echo '"<table>';
echo '<tr>';
echo '<th>Name</th>';
echo '<th>Driver</th>';
echo '<th>Last Seen</th>';
echo '<th>Follow</th>';
echo '<th>Status</th>';
echo '<th>Speed</th>';
echo '<th>Engine</th>';
echo '<th>Address</th>';
echo '</tr>';
while ($db->fetch_array()){
$timezone = $db->get('gp_timezone');
$sql2 = "SELECT *, date_add(gm_gpstime, INTERVAL ".$timezone." HOUR) gpstime FROM gps_msg
WHERE gm_imei = '" . $db->get('gp_imei') . "' AND gm_event = '0' ORDER BY gm_gpstime desc LIMIT 1;";
$db2 = new DbClass($sql2);
while ($db2->fetch_array()) {
echo '<tr id=\''.$db->get("gp_imei").'\' class=\'Vehicle\'>';
echo '<td>';
echo $db->get("gp_name");
echo '</td>';
echo '<td>';
if ($db->get("gp_sopir"))
echo $db->get("gp_sopir");
echo '</td>';
echo '<td>';
echo ago(time() - timeToSecond($db2->get('gpstime'), 0));// berapa detik yang lalu
echo '</td>';
echo '<td>';
echo '<center><input type=\'checkbox\' class=\'checkbox\' id=\'';
echo $db->get("gp_imei");
echo '\'></input></center>';
echo '</td>';
echo '<td>';
$mode = cekStatusGPS($db2->get('gm_accuracy'), substr($db2->get('gm_devicestate'),0,2));
echo '<center><img src=\'status/'.$mode.'.png\' width=\'20px\' height=\'20px\'></center>';// status
echo '</td>';
echo '<td>';
echo $db2->get('gm_speed').'km/h';// Kecepatan
echo '</td>';
echo '<td><center>';
if (substr($db2->get('gm_devicestate'),0,1) == '1'){
$engine = 'off';
}
else if(substr($db2->get('gm_devicestate'),0,1) == '2'){
$engine = 'on';
}
echo $engine;// engine on/off
echo '</center></td>';
echo '<td>';
if ($db->get('gp_rgeo') == 1) {
$posisi = parse_location($db2->get('jalan'). "," . $db2->get('kota'). "," . $db2->get('kabupaten'). "," . $db2->get('propinsi'). "," . $db2->get('negara'). "," . $db2->get('landmark'));
}
else{
$posisi = result_location($db2->get('gm_lat'),$db2->get('gm_lng'));
}
echo $posisi;// alamat
echo '</td>';
echo '</tr>';
}
}
echo '</table>"';
?>
);
}
$(document).ready(function() {
$('#Map').html('<object data="map.php?user=<?php echo $_SESSION['
user_name ']?>" width="100%" height="100%">');
$(function() {
vehicle();
setInterval(vehicle, 60000);
});
$('.checkbox').change(function() {
if (this.checked) {
$('#Map').html('<object data="map.php?imei=' + this.id + '" width="100%" height="100%">');
$('.checkbox').not(this).prop('checked', false);
} else {
$('#Map').html('<object data="status.php?user=<?php echo $_SESSION['
user_name ']?>" width="100%" height="100%">');
}
});
$('.Vehicle').dblclick(function() {
$('#Status').html('<object data="status.php?imei=' + this.id + '" width="100%" height="100%">');
});
});
</script>
功能车辆(){
$(“#车辆”).html(
由于您通过PhP的echo
向页面添加了元素,因此必须使用
因此,不要使用$('.checkbox').change(function(){});
将其更改为$('#Vehicles')。更改('change','.checkbox',function(){});
并将该更改添加到您的echo
请注意,这将使您的PhP变得凌乱,因此我建议将绑定转换为js函数,然后在echo上调用该函数您是否意识到PhP代码永远不会更新?每次间隔运行时都是一样的!!为什么它不起作用…因为事件不会神奇地保持绑定。所以重复答案是什么但是这个表永远不会得到新的数据。这需要使用Ajax。