簡體   English   中英

選擇單選按鈕時,如何更改下拉注釋?

[英]How do I change dropdown comments when a radiobutton is selected?

<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條件中?

這不能完全用刀片完成​​,您還需要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();
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM