我使用jQuery創建了一個選擇框。這裏是我的小提琴:http://jsfiddle.net/andreaszeike/gff1r5dr/3/jquery if then each arrays
它的正常工作媒體鏈接,但你可以幫我速記代碼:
$(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/),但我並沒有設法將其轉移我的例如jet。
...非常感謝,這是爲我做的! –