这是组合框的代码
<select name="cmbdegree" id="cmbdegree" class="styledselectevents">
<option value="0">Select Degree</option>
<?php
$newque="SELECT * FROM degrees";
$qu=mysqli_query($conn, $newque);
while($rs=mysqli_fetch_array($qu))
{
?>
<option value="<?=$rs['id']?>" <?php if($rs['id'] === $rsSemDegID) { echo 'Selected'; } ?>><?=$rs['Title']?></option>
<?PHP } ?>
</select>
现在我有一个JQuery来运行更改
$(document).on('change', '#cmbdegree', function() {
var val = $(this).val();
$.ajax({
url: 'gettotalsemesters.php',
data: {
cmbdegree: val,
seldeg: $rsSemDegID
},
type: 'GET',
dataType: 'html',
success: function(result) {
$('#SemsterNum').html();
$('#SemsterNum').html(result);
},
error: function() {
alert('Error occured');
}
});
});
当用户更改它时它可以工作..但我希望它在PHP脚本完成选择时引发更改事件。
答案 0 :(得分:1)
尝试此操作,页面加载后触发更改事件
$(document).on('change', '#cmbdegree', function() {
var val = $(this).val();
$.ajax({
url: 'gettotalsemesters.php',
data: {
cmbdegree: val,
seldeg: $rsSemDegID
},
type: 'GET',
dataType: 'html',
success: function(result) {
$('#SemsterNum').html();
$('#SemsterNum').html(result);
},
error: function() {
alert('Error occured');
}
});
});
$('#cmbdegree').trigger("change"); //<--------trigger event