这是我拥有的下拉代码,它根据所做的选择创建一个查询字符串。我要弄清楚的唯一一项是如何在页面重新加载时保留选择。
<html>
<select id="categoryFilter">
<option value=""></option>
<option name="Category1" id=Category1 value=".">All</option>
<option name="Category2" id=Category2 value="2.1">Processors</option>
<option name="Category3" id=Category3 value="2.4">GPU</option>
<option name="Category4" id=Category4 value="1">Corporate</option>
</select>
<script>
function setSelectedIndex(s, valsearch)
{
// Loop through all the items in drop down list
for (i = 0; i< s.options.length; i++)
{
if (s.options[i].value == valsearch)
{
// Item is found. Set its property and exit
s.options[i].selected = true;
break;
}
}
return;
}
function Filter_Init()
{
var fvalue= JSRequest.QueryString['categoryFilter'];
setSelectedIndex(document.getElementById('categoryFilter'), decodeURI(fvalue));
}
$('#categoryFilter').change(function() {
window.location = 'http://' + location.hostname + location.pathname + '?' + $("#categoryFilter option:selected").attr('id') + '=' + $("#categoryFilter option:selected").val() + '#2';
Filter_Init();
});