我使用 ajax 自动从数据库加载选择数据
<div class="row-form">
<div class="span2">Condition:</div>
<div class="span4 input-prepend">
<span class="add-on blue"><i class="icon-arrow-down icon-white"></i></span>
<select name="condition" id="condition" class="validate[required]" >
</select>
</div>
</div>
//ajax function to load condition to select box
$.ajax({
url:'search/condition.php',
type:'POST',
async:true,
success: function(data){
$("#condition").html(data);
}
});
ajax 的 PHP 代码:-
<?php
require("../dbconnect.php");
$qry="SELECT * FROM condition_master";
$rs=mysqli_query($con,$qry);
$data .= "<option value=''>Select condition</option>";
while($row=mysqli_fetch_array($rs)){
$des=$row['condition_des'];
$data .= "<option value='$des'>$des</option>";
}
echo $data;
?>
它正确加载..但是在尝试使用jquery自动选择条件时,它没有正确选择
<script>
$(function(){
$("#condition").val('used');
});
</script>