2013-02-13 93 views
1

我有一個選擇選項選擇選項顯示事業部及隱藏一個DIV - JQuery的

<select class="input_select" name="customer_type" id="central_company"> 
    <option value="standard">Standard</option> 
    <option value="central">Central Station</option> 
</select> 

和一個按鈕

<div class="standardbutton"> 
    <label class="button_label"> 
     <input type="submit" class="standardbutton" name="button1" value="Submit Form" /> 
    </label> 
</div> 

,單擊時使用這個jQuery

// Show Special Form Elements 
$(".cleantestbox").hide(); 
$('#central_company').change(function() { 
    var option = $(this).find('option:selected'); 
    $('.cleantestbox').toggle(option.hasClass('central')); 
    $('.standardbutton').toggle(option.hasClass('standard')); 
}).change(); 

隱藏標準按鈕類,並顯示一個名爲.cleantestbox的div,但它似乎沒有工作。它以前的任何想法,但似乎無法找到什麼導致它不工作。

+2

你在控制檯中遇到什麼樣的錯誤? – dezman 2013-02-13 16:24:37

+1

它以什麼方式不起作用?把你的代碼放在小提琴中:http://jsfiddle.net/ – isherwood 2013-02-13 16:24:53

+0

沒有錯誤只是當我選擇中央沒有任何反應,標準按鈕div默認不顯示 – Nexus9988 2013-02-13 16:28:29

回答

1
// Show Special Form Elements 
$(".cleantestbox").hide(); 
$('#central_company').change(function() { 
    if ($(this).val() == 'central') { 
    $('.cleantestbox').show(); 
    $('.standardbutton').hide(); 
    } else { 
    $('.cleantestbox').hide(); 
    $('.standardbutton').show(); 
    } 
}); 
+0

謝謝!像魅力一樣工作! – Nexus9988 2013-02-13 17:07:23