我正在使用JQuery選擇插件來欣賞我的選擇選項。插件本身工作正常。不過,我的一些下拉列表使用AJAX POST過濾/拉回另一個選擇中的精選列表。JQuery選擇:不更新在後臺選擇選項
JQuery插件被添加並且沒有改變。但由於某種原因,當我在Select中篩選次要選擇中的選項時,次要選擇似乎不能識別出已選擇了一個選項。
任何想法?有沒有人遇到過這個問題?
<div class="search-line">
<div class="search-option">
<label>Asset Type:</label>
<select name="AssetType" id="AssetType">
<?php
$type_sql = "SELECT DISTINCT AssetType.AssetTypeTitle AS HardwareAssetAssetTypeTitle, HardwareAssetAssetTypeID FROM HardwareAsset INNER JOIN AssetType ON (AssetType.AssetTypeID = HardwareAsset.HardwareAssetAssetTypeID) ORDER BY HardwareAssetAssetTypeTitle ASC";
$type = sqlsrv_query($database_connection, $type_sql);
if (!sqlsrv_has_rows($type)){
echo "<option>No Records Found</option>";
}
else{
echo "<option value= ''>Select Asset Type</option>";
while($type_option = sqlsrv_fetch_object($type)){
echo "<option value='$type_option->HardwareAssetAssetTypeID'>".$type_option->HardwareAssetAssetTypeTitle."</option>";
}
}
?>
</select>
</div>
<div class="search-option">
<label>Asset Sub-Type:</label>
<select name="AssetSubType" id="AssetSubType">
<option value="">Select Asset Type First</option>
</select>
</div>
</div>
AJAX:
$('#AssetType').on('change',function(){
var AssetAssetTypeID = $(this).val();
if(AssetAssetTypeID != 0){
$.ajax({
type:'POST',
url:'/ITSMIS/data/asset/search.php',
data:'AssetAssetTypeID='+AssetAssetTypeID,
success:function(data){
$('#AssetSubType').html(data);
}
});
}
else{
$('#AssetSubType').html('<option value="">Select Asset Type First</option>');
}
});
能否請您發佈你寫的平變化的功能爲第一選擇? –
更新與onchange,希望有所幫助? – TheTechnicalPaladin