我想在选择列表中选择一个选项并将代码触发到更改功能。
PHP请求代码:
$la_reservation = $dbh->prepare("SELECT *,
Date_debut, Date_fin,
client.Nom_societe, Personne_de_contact_idPersonne_de_contact,
IdAdresse, adresse.Rue, adresse.Numero, adresse.Boite, adresse.Code_postal, adresse.Localite, adresse.Pays, adresse.Email, Tel1, adresse.Client_IdClient
FROM bail
LEFT JOIN reservation ON idBail = Ref_bail
LEFT JOIN client ON bail.Ref_filiale = client.IdClient
LEFT JOIN personne_de_contact ON Personne_de_contact_idPersonne_de_contact = idPersonne_de_contact
LEFT JOIN adresse ON adresse.Client_IdClient = client.IdClient
WHERE idBail = :num_reservation");
$data = array(":num_reservation"=>$_GET['num_res']);
//echo str_replace(array_keys($data), array_values($data), $la_reservation->queryString);
$la_reservation->execute($data);
$res = $la_reservation->fetch();
我使用$ res ['IdClient']来指示我想在选择列表中选择哪个选项:
<script>$('#liste_clients').val("<?php echo $res['IdClient']?>");</script>
生成的代码是:
<script>$('#liste_clients').val("14");</script>
但更改功能中的警报无效:
$("#liste_clients").change(function(){
alert("here");
....
}
答案 0 :(得分:0)
使用.on()
事件,因为数据会动态添加到页面中。
$(document).on("change", "#liste_clients", function(event){
alert("changed");
});
答案 1 :(得分:0)
试试这个:
<script>
$(document).ready(function(){
$('#liste_clients option[value=14]').attr('selected', 'selected');
$('#liste_clients').trigger('change');
});
</script>