に二回登場するので、私はこのjqueryのを持っている:はjqueryのアラートがfocusout
$("#dynamic_admin_edit_event_time").on("focusout", ".jamAkhir", function() {
var $row = $(this).closest("tr"); // Find the row
var row_time_id_edit = $row.find(".row_time_id_edit").text();
var jam_awal = $row.find(".jamMulai").val();
var jam_akhir = $row.find(".jamAkhir").val();
if(jam_awal >= jam_akhir && jam_akhir !== '') {
$("#edit_jam_akhir_"+ row_time_id_edit).css("border-color", "red");
alert("Jam akhir event tidak boleh lebih dahulu dari jam mulai event");
$(this).addClass('error');
//$(".edit_event").prop("disabled",true);
}
else if(jam_akhir === ''){
}
else if(jam_awal < jam_akhir){
$("#edit_jam_mulai_"+ row_time_id_edit).css("border-color", "lightgrey");
$("#edit_jam_akhir_"+ row_time_id_edit).css("border-color", "lightgrey");
$(this).removeClass('error');
}
});
それでは、これがないと、クラス.jamakhirとテキスト入力が満たされたときに、それは、クラス.jamAwalに確認するだろうということです同じ行、チェックは正常に動作しますが、問題は、エラーを表示するアラートメッセージ(.jamAwalの値が.jamAkhirの値より大きい場合)が、ifステートメント、それは一度だけ表示されるようにするにはどうすればいいですか?
EDIT:このjqueryのためのHTMLコード:
$get_date = "SELECT tgl_event, Jam_Mulai_event, jam_akhir_event, id_jadwal_acara
FROM jadwal_acara
WHERE id_event = '$id_event'
AND status = '$one'";
$result_get_date = mysqli_query($db, $get_date);
$count_date = 1;
while($show_date = mysqli_fetch_array($result_get_date)) {
$tgl_event = $show_date['tgl_event'];
$jam_mulai_event = $show_date['Jam_Mulai_event'];
$jam_akhir_event = $show_date['jam_akhir_event'];
$id_jadwal_acara = $show_date['id_jadwal_acara'];
if($count_date == 1) {
$output .= '
<tr>
<td><input type="text" name="admin_edit_exist_tgl_event[]" class="form-control edittglEvent" value="' .$tgl_event. '" required></td>
<td><input type="text" name="admin_edit_exist_jam_mulai_event[]" class="form-control jamMulai" id="edit_jam_mulai_'.$count_date.'" value="' .$jam_mulai_event. '" style="border-color: lightgrey" required></td>
<td><input type="text" name="admin_edit_exist_jam_akhir_event[]" class="form-control jamAkhir" id="edit_jam_akhir_'.$count_date.'" value="' .$jam_akhir_event. '" style="border-color: lightgrey" required></td>
<td style="display:none;"><input type="text" name="admin_edit_exist_id_jadwal_acara[]" class="form-control" value="' .$id_jadwal_acara. '" required></td>
<td><button type="submit" name="button_edit_add_event_time" id="edit_add_event_time" class="btn btn-success">Add More Event</button></td>
';
$plus = "<td class='row_time_id_edit' style='visibility: hidden;'>$count_date</td></tr>";
$output .= $plus;
$count_date++;
}
else if($count_date != 1){
$output .= '
<tr id="edit_row_'.$count_date.'">
<td><input type="text" name="admin_edit_exist_tgl_event[]" class="form-control edittglEvent" value="' .$tgl_event. '" required></td>
<td><input type="text" name="admin_edit_exist_jam_mulai_event[]" class="form-control jamMulai" id="edit_jam_mulai_'.$count_date.'" value="' .$jam_mulai_event. '" style="border-color: lightgrey" required></td>
<td><input type="text" name="admin_edit_exist_jam_akhir_event[]" class="form-control jamAkhir" id="edit_jam_akhir_'.$count_date.'" value="' .$jam_akhir_event. '" style="border-color: lightgrey" required></td>
<td style="display:none;"><input type="text" name="admin_edit_exist_id_jadwal_acara[]" class="form-control" value="' .$id_jadwal_acara. '" required></td>
<td><button type="submit" name="button_edit_remove_exist_event_time" id="' .$count_date. '" class="btn btn-danger btn_remove_exist">Remove Event</button></td>
<td class="row_time_id_edit" style="visibility: hidden;">'.$count_date.'</td></tr>
</tr>
';
$count_date++;
}
else{
echo"Something Went Wrong";
}
}
時間をチェックしても問題はありませんが、問題は、アラートが二回登場していることですが、チェックは間違っていないです。
これはうまく見えます。 –
いいえ、私は一度だけ入れます。 – teddygamer