似乎无法解决这个问题。价值确实会发生变化,但是" #donateForm"在选择原始选项时不会隐藏。
<select id="donateSelect">
<option value="0">Select</option>
<option value="General Fund">General Fund</option>
<?php
// display all project names as options
$prj_sql = "SELECT `name` FROM `tbl_projects`";
$prj_result = mysqli_query($database_link, $prj_sql);
while ($prj = mysqli_fetch_array($prj_result)) {
echo '<option value="'.$prj['name'].' Project Fund">'.$prj['name'].' Project Fund</option>';
}
?>
</select>
<div id="donateForm">
......
</div>
<script>
$('#donateForm').hide();
$('#donateSelect').on('change', function() {
if ($('#donateSelect').val() == "0") {
$('#donateForm').hide();
} else {
var donateValue = $(this).find('option:selected').attr('value');
$('#donateForm').show();
$('#item_name').val(donateValue);
}
});
</script>