0

value="" に基づいて選択ドロップダウンで div を表示および非表示にしようとしています。

なぜこれが機能しないのか、誰かが私に説明してもらえますか? これがJfiddleです:http://jsfiddle.net/JNyce/11/

$('.section_container').children().hide();
$('#form_selection').change(function() {


  var selection = $(this).parent().find("option:selected").text();

    var newselection = selection.split(' ').join('_');

    $('.section_container'+newselection).show();

    });

html

<div class="box" style="border: 1px solid black; margin-top:100px;">
<select id="form_selection">
<option value="Program 1">Program 1</option>
<option value="Program 1">Program 2</option>
</select>

        <div class="section_container">
            <div class="Program_1" style="height:200px; border:1px solid black"> 
            <div class="title">Testing</div>
            <span> orem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing</span>
            <div class="section_logo" style="width:100px; height:100px; float:left;"><img src="http://www.dublin.k12.ca.us/cms/lib5/CA01001424/Centricity/Domain/35/homeschool.jpg"> </div><button class="blue-pill" style="float:right;">Select Program</button>
            </div>

            <div class="Program_2" style="height:200px; border:1px solid black"> 
            <div class="title">Testing</div>
            <span>orem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing </span>
            <div class="section_logo" style="width:100px; height:100px; float:left;"><img src="http://www.dublin.k12.ca.us/cms/lib5/CA01001424/Centricity/Domain/35/homeschool.jpg"> </div>
             <button class="blue-pill" style="float:right;">Select Program</button>
            </div>
     </div>
4

2 に答える 2

3

まず、次のvalue="Program 1"2つがあります。

<option value="Program 1">Program 1</option>
<option value="Program 1">Program 2</option>

これは次のようになります。

<option value="Program 1">Program 1</option>
<option value="Program 2">Program 2</option>

次に、クラスを正しく選択していません。

$('.section_container' + newselection).show();

これは次のようになります。

$('.section_container .' + newselection).show();

デモ

Javascript

$('.section_container > div').hide();
$('#form_selection').change(function () {

    var selection = $(this).val();
    var newselection = selection.replace(' ', '_');

    $('.section_container > div').hide();
    $('.section_container .' + newselection).show();

});
于 2013-06-26T03:53:45.083 に答える
1

フィドルはこちら

$('.section_container').children().hide();
$('#form_selection').change(function () {


    var selection = $(this).parent().find("option:selected").text();

    var newselection = selection.split(' ').join('_');
    console.log(newselection);

    $('.section_container').children().hide();
    $('.section_container').find('.' + newselection).show();
});
于 2013-06-26T03:59:18.833 に答える