我有我的脚本工作,但目前它使用按钮输入,我想将其更改为选择框输入,但我似乎无法让代码工作,请帮助
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function() {
var fuel = ''; // Keep track of selections
var drive = '';
var type = '';
$('#fuel button').click(function() { // Choose a fuel
fuel = (this.id ? '.' : '') + this.id;
selectModels();
});
$('#drive button').click(function() { // Choose a drive
drive = (this.id ? '.' : '') + this.id;
selectModels();
});
$('#type button').click(function() { // Choose a colour
type = (this.id ? '.' : '') + this.id;
selectModels();
});
function selectModels() { // Select matching models
$('div.modelContainer').hide(). // Hide all
filter((fuel + drive + type) || '*').show(); // Show matches
}
});
</script>
</head>
<body>
<div id="fuel" class="controller">
<span class="controllerLabel">fuel:</span>
<button>All</button>
<button id="petrol">petrol</button>
<button id="diesel">diesel</button>
</div>
<div id="drive" class="controller">
<span class="controllerLabel">drive:</span>
<button>All</button>
<button id="man">manual</button>
<button id="auto">auto</button>
</div>
<div id="type" class="controller">
<span class="controllerLabel">type:</span>
<button>All</button>
<button id="car">car</button>
<button id="4">4x4</button>
<button id="7">people</button>
<button id="van">van</button>
</div>
<div class="modelContainer petrol manual car">
pmc
</div>
<div class="modelContainer petrol manual 4">
pm4
</div>
<div class="modelContainer petrol auto car">
pac
</div>
<div class="modelContainer diesel manual car">
dmc
</div>
<div class="modelContainer diesel manual van">
dmv
</div>
<div class="modelContainer diesel auto car">
dac
</div>
<div class="modelContainer diesel auto 4">
da4
</div>
<div class="modelContainer diesel auto 7">
da7
</div>
<div class="modelContainer diesel auto 7 4">
sor
</div>
</body>
</html>
并将“燃料”按钮更改为
<div id="fuel" class="controller">
<span class="controllerLabel">fuel:</span>
<select>
<option value="all">all</option>
<option value="petrol">petrol</option>
<option value="diesel">diesel</option>
</select>
</div>
谢谢