我做了以下工作,很好。它從下拉菜單中更改Div onSelectChange的背景。我確信有更好的方式。有人可以推薦嗎?從選擇變更Div的背景
謝謝你看。
$(document).ready(function() {
$("#QuoteRequiredFor").change(onSelectChange);
});
function onSelectChange() {
var selected = $("#QuoteRequiredFor option:selected");
var output = "";
if (selected.val() == '') {
output = "You Selected " + selected.text();
$('#FinanceQuoteForm').css('background', 'url(/Finance-Quote/FinanceQuoteForm/images/FFheaderQuoteFactoring.jpg)');
};
if (selected.val() == 'Factoring') {
output = "You Selected " + selected.text();
$('#FinanceQuoteForm').css('background', 'url(/Finance-Quote/FinanceQuoteForm/Images/factoring.jpg)');
};
if (selected.val() == 'Mortgage') {
output = "You Selected " + selected.text();
$('#FinanceQuoteForm').css('background', 'url(/Finance-Quote/FinanceQuoteForm/Images/Mortgage.jpg)');
};
if (selected.val() == 'Stock') {
output = "You Selected " + selected.text();
$('#FinanceQuoteForm').css('background', 'url(/Finance-Quote/FinanceQuoteForm/Images/stock.jpg)');
};
if (selected.val() == 'Asset') {
output = "You Selected " + selected.text();
$('#FinanceQuoteForm').css('background', 'url(/Finance-Quote/FinanceQuoteForm/Images/asset.jpg)');
};
if (selected.val() == 'Invoice discounting') {
output = "You Selected " + selected.text();
$('#FinanceQuoteForm').css('background', 'url(/Finance-Quote/FinanceQuoteForm/Images/factoring.jpg)');
};
$("#output").html(output);
}
恩,由於縮進不一致造成的小監督,你在'else' cluase中丟失了設置輸出 – 2011-04-23 13:57:03
@Shrikant:謝謝,指點我。 – Gaurav 2011-04-23 13:59:03
非常感謝您抽出時間。使我的嘗試看起來笨重。 – Bocker 2011-04-23 14:16:33