我正在使用 ajax/jquery 加载商店列表,但是当用户选择商店时,它不会在页面刷新时保持选中该选项。它一直回到默认值(查看全部),我尝试用选项做 cfif 语句,但它似乎不起作用
HTML:
<label for="LocationTypeID">Market:</label>
<select id="LocationTypeID" name="LocationTypeID" class="ddRefreshFilters">
<option value="-999">[ All Markets ]</option>
<cfloop query="qUserLocationTypes">
<option value="#qUserLocationTypes.LocationTypeID#" <cfif qUserLocationTypes.LocationTypeID IS Request.Attributes.LocationTypeID>selected</cfif>>#qUserLocationTypes.Name#</option>
</cfloop>
</select>
<label for="Store_LocationID">Store:</label>
<select id="Store_LocationID" name="Store_LocationID" class="ddRefreshFilters">
</select>
j查询:
<script>
$(document).ready(function()
{
$('#LocationTypeID').change(function()
{
var LocationTypeID = $(this).val();
var Store_LocationID = $('#Store_LocationID').val();
$.ajax({
url: '/_scripts/ajax/listStores.cfm',
type: 'post',
data: {LocationTypeID:LocationTypeID},
dataType: 'json',
success: function(data)
{
var len = data.length;
$('#Store_LocationID').empty();
$('#Store_LocationID').append('<option value="-999">View All</option>');
for( var i = 0; i<len; i++) {
var id = data[i]['locationid'];
var name = data[i]['name'];
$('#Store_LocationID').append("<option value='"+id+"' <cfif Request.Attributes.Store_LocationID IS '"+id+"'>selected</cfif>>"+name+"</option>");
}
}
}
);
});
if ($('#LocationTypeID').val().length > 0)
{
$('#LocationTypeID').change();
}
$('.ddRefreshFilters').change(function()
{
var Store_LocationID = $('#Store_LocationID').val();
var LocationTypeID = $('#LocationTypeID').val();
var Url = '/dashboard/ss/StepTypeSummary.cfm?'&LocationTypeID=' + LocationTypeID + '&Store_LocationID=' + Store_LocationID;
location.href = Url;
});
});
</script>