2013-03-02 53 views
0

如果我選擇從第一個選擇框中碩士選項,然後在第二個選擇框會顯示只有MBA /金融和MBA /營銷選項,從第三個選擇框將顯示學士學位,碩士學位和博士學位。 現在如果讓我選擇從第一個選擇框中學士學位選項,然後在第二個選擇框會顯示只有BCJ /執法和BCJ /更正選項,並從第三個選擇框,它會顯示所有選項。 我已經做了幾個代碼,但它不工作。三個選擇框,但是當我第一次選擇一個未來兩年將改變-HTML JavaScript或jQuery的

<select id="degree"> 
<option value="default">Choose a degree</option> 
<option value="Master">Master Degree</option> 
<option value="Bachelor">Bachelor Degree</option> 

<select id="program"> 
<option value="default">Choose a program</option> 
<option value="MBA/FN" Degree="Master">MBA/Finance</option> 
<option value="MBA/MK" Degree="Master">MBA/Marketing</option> 
<option value="BCJ/LE" Degree="Bachelor">BCJ/Law Enforcement</option> 
    <option value="BCJ/COR" Degree="Bachelor">BCJ/Corrections</option> 

<select id="level"> 
<option selected="selected" value="">Choose Highest level of Education</option> 
    <option value="Less than 2 years of college">Less than 2 years of college</option> 
    <option value="2 or more years of college">2 or more years of college</option> 
    <option value="Associate Degree">Associate Degree</option> 
    <option value="Bachelor Degree">Bachelor Degree</option> 
    <option value="Master Degree">Master Degree</option> 
    <option value="Doctorate Degree">Doctorate Degree</option> 

+0

有您搜索的StackOverflow?這個問題或類似的問題已被多次詢問(依賴,鏈接或級聯下拉),這可能有助於http://stackoverflow.com/questions/5910281/jquery-dependent-drop-down-boxes-populate-how。另外,你到目前爲止嘗試過什麼?你的JavaScript在哪裏? – thaJeztah 2013-03-02 11:28:00

+0

感謝您的回覆。 我有箱子文件http://jsfiddle.net/Sheikh_musa/FptkX/1/請檢查一下,我真的需要幫助來自不同資源的只是學習的Jscript。 謝謝 – 2013-03-02 12:42:36

回答

0

HTML

按你的選擇框...

<select id="degree"> 
<option value="default">Choose a degree</option> 
<option value="Master">Master Degree</option> 
<option value="Bachelor">Bachelor Degree</option> 

<select id="program"> 
<option value="default">Choose a program</option> 

<optgroup class="level1"> 
<option class="level1" value="MBA/FN" Degree="Master">MBA/Finance</option> 
<option class="level1" value="MBA/MK" Degree="Master">MBA/Marketing</option> 
</optgroup> 
<optgroup class="level2"> 
<option class="level2" value="BCJ/LE" Degree="Bachelor">BCJ/Law Enforcement</option> 
<option class="level2" value="BCJ/COR" Degree="Bachelor">BCJ/Corrections</option> 
</optgroup> 
<select id="level"> 

<option selected="selected" value="">Choose Highest level of Education</option> 
    <optgroup class="level3"> 
    <option class="level3" value="Less than 2 years of college">Less than 2 years of college</option> 
    <option class="level3" value="2 or more years of college">2 or more years of college</option> 
    </optgroup> 
    <optgroup class="level1"> 
    <option class="level1" value="Associate Degree">Associate Degree</option> 
    <option class="level1" value="Bachelor Degree">Bachelor Degree</option> 
    </optgroup> 
    <optgroup class="level2"> 
    <option class="level2" value="Master Degree">Master Degree</option> 
    <option class="level2" value="Doctorate Degree">Doctorate Degree</option> 
    </optgroup> 

SCRIPT

$('#degree').change(function() { 
     if ($('#degree option:selected').text() == "Master"){ 
       $('.level1').css('display', 'block'); 
       $('.level2').css('display', 'none'); 
       $('.level3').css('display', 'none'); 
     } else if ($('#degree option:selected').text() == "Bachelor"){ 
       $('.level1').css('display', 'none'); 
       $('.level2').css('display', 'block'); 
       $('.level3').css('display', 'none'); 
     } else { 
       $('.level1').css('display', 'block'); 
       $('.level2').css('display', 'block'); 
       $('.level3').css('display', 'block'); 
     }}); 
+0

感謝您的回覆。 我打包一個文件http://jsfiddle.net/Sheikh_musa/FptkX/1/,請檢查它我真的需要幫助只是從不同的資源學習Jscript。 感謝 – 2013-03-02 12:43:05

+0

SASI可以請你告訴我哪jQuery的文件,我必須使用此請如果工作提供當然投票的鏈接我會的。 – 2013-03-02 12:53:34

+0

看只是您可以組織與選項選項組和隱藏他們的選擇..我將更新更好的代碼,並解釋你如何做到這一點.. – sasi 2013-03-02 13:03:03

相關問題