我正在尝试设置下拉菜单,并让最终选择带您到URL.我可以使各种下拉工作,但浏览器在您做出最终选择后没有做任何事情.
我可以靠近,但后来我失去了隐藏不适用的其他下降的能力!
<tr>
<td>
<p align="center">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label for="qmt-vehicle">Vehicle:</label>
<select id="qmt-vehicle" name="vehicle">
<option></option>
<option class="BMW" value="BMW">BMW</option>
<option class="Audi" value="Audi">Audi</option>
</select>
<p align="center">
<label for="qmt-manufacturer">Manufacturer:</label>
<select id="qmt-manufacturer" name="manufacturer">
<option></option>
<option class="BMW" value="http://www.google.com">BMW</option>
<option class="BMW" value="http://www.google.com"> M3</option>
<option class="BMW" value="http://www.google.com"> M5</option>
<option class="Audi" value="Audi">Audi</option>
<option class="Audi" value="http://www.google.com"> A4</option>
<option class="Audi" value="http://www.google.com"> S4</option>
</select>
<script>
$(function() {
$("#qmt-vehicle").on("change", function() {
var levelClass = $('#qmt-vehicle').find('option:selected').attr('class');
console.log(levelClass);
$('#qmt-manufacturer option').each(function() {
var self = $(this);
if (self.hasClass(levelClass)
|| typeof(levelClass) == "undefined") {
self.show();
} else {
self.hide();
}
});
});
});
</script>
<p align="center">
</td>
</tr>
最佳答案 您只需将其添加到脚本中:
$("#qmt-manufacturer").on("change",function()
{
window.location.href = $('#qmt-vehicle').find('option:selected').attr("value");
});