【发布时间】:2017-03-29 08:59:18
【问题描述】:
我使用 jQuery 创建了一个选择框。这是我的小提琴:http://jsfiddle.net/andreaszeike/gff1r5dr/3/
一切正常,但你能帮我简写一下代码吗:
$(document).ready(function () {
$('#link-button a ').attr("href", "http://test/")
});
$('select[name=model]').change(function () {
//keine Auswahl
if ($(this).val() == '') {
$(document).ready(function () {
$('#link-button a ').attr("href", "http://test/")
});
} else
//alfa-Romeo
if ($(this).val() == 'ar-1') {
$(document).ready(function () {
$('#link-button a ').attr("href", "http://test/alfa-romeo/giulietta/")
});
} else
if ($(this).val() == 'ar-2') {
$(document).ready(function () {
$('#link-button a ').attr("href", "http://test/alfa-romeo/mito/")
});
} else
if ($(this).val() == 'ar-3') {
$(document).ready(function () {
$('#link-button a ').attr("href", "http://test/alfa-romeo/spider/")
});
} else
//Alpina
if ($(this).val() == 'alp-1') {
$(document).ready(function () {
$('#link-button a ').attr("href", "http://test/alpina/alpina-b3/")
});
} else
if ($(this).val() == 'alp-2') {
$(document).ready(function () {
$('#link-button a ').attr("href", "http://test/alpina/alpina-b5/")
});
} else
if ($(this).val() == 'alp-3') {
$(document).ready(function () {
$('#link-button a ').attr("href", "http://test/alpina/alpina-b10/")
});
} else
if ($(this).val() == 'alp-4') {
$(document).ready(function () {
$('#link-button a ').attr("href", "http://test/alpina/alpina-rs/")
});
} else {}
});
我找到了一些示例 (https://www.sitepoint.com/jquery-each-function-examples/),但我没有设法将其转移到我的示例喷气机上。
【问题讨论】: