选择单选按钮后,如何更改下拉注释?

时间:2016-05-19 15:31:15

标签: php laravel if-statement foreach laravel-blade

<select class="form-control" id="select">
    @if(document.getElementById('radiobuttonID')=='pages')
         @foreach($page as $row)
            <option class='opt' id='{{ $row->id}}' data-id='{{ $row->id}}'>{{$row->name}}</option>
         @endforeach
    @else
         //Do the else thing
    @endif
</select>

这肯定不行,但我希望你能看到这个想法(把上面的内容作为伪代码)。有没有办法将ID存储到变量中,然后将其置于if条件下?

1 个答案:

答案 0 :(得分:0)

这不能单纯用刀片完成​​,你也需要javascript,我建议:

<select class="form-control" id="select1">

     @foreach($page as $row)
        <option class='opt' id='{{ $row->id}}' data-id='{{ $row->id}}'>{{$row->name}}</option>
     @endforeach
</select>

<select class="form-control" id="select2" style="display:none;">
    // do the else thing
</select>

然后使用javascript(和jquery):

$('#radiobuttonID').change(function(event){
    if($(this).is(':checked')) 
    {
        $('#select1').show();
        $('#select2').hide();
    }else{
        $('#select2').show();
        $('#select1').hide();
    }
});
相关问题