簡體   English   中英

如何通過選擇單選按鈕選項來更改文本表單字段

[英]How to change text form fields by selecting radio button options

我有兩個選項1-休假2-長期現在,我要在此處的是從單選按鈕中選擇這些選項時所填寫的表單,表單具有以下字段:

1-季節2-日期3-每日4-每周5-每月

現在,當我選擇長期值時,我想在這里只顯示彈出窗口中的“每月”字段,如果選擇“休假”,則應顯示所有字段。

這些選項在我的html中:

     <div class="m-b-10 m-t-10">

            <label class="radio-inline">
              <input type="radio" id="inlineCheckbox1" value="is_vacation" name="property_type" checked> Vacation
            </label>
            <label class="radio-inline">
              <input type="radio" id="inlineCheckbox2" value="is_long_term" name="property_type"> Long Term
            </label>

        </div>

和我的控制器

      if ($search == "vacationRental") {

            // $properties = Property::where('is_vacation', '=', 1)->get();
            $properties = Property::where('status', '=', 1)->where('is_vacation', '=', 1)->get();
            return view('admin.property.index')
                        ->with('properties', $properties)
                        ->with('seasons', $seasons);

        } elseif ($search == "longTerm") {

            // $properties = Property::where('is_long_term', '=', 1)->get();
            $properties = Property::where('status', '=', 1)->where('is_long_term', '=', 1)->get();
            return view('admin.property.index')
                        ->with('properties', $properties)
                        ->with('seasons', $seasons);

        }

我需要為此創建一個新視圖,還是可以使用JS完成,我認為可以使用JS完成,但是我不知道如何執行此操作。 需要你的幫助

非常感謝您的幫助!

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Show Hide Elements Using Radio Buttons</title> <style type="text/css"> .box{ color: #fff; padding: 20px; display: none; margin-top: 20px; } .red{ background: #ff0000; } .green{ background: #228B22; } .blue{ background: #0000ff; } label{ margin-right: 15px; } </style> <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('input[type="radio"]').click(function(){ var inputValue = $(this).attr("value"); var targetBox = $("." + inputValue); $(".box").not(targetBox).hide(); $(targetBox).show(); }); }); </script> </head> <body> <div> <label><input type="radio" name="colorRadio" value="red"> red</label> <label><input type="radio" name="colorRadio" value="green"> green</label> <label><input type="radio" name="colorRadio" value="blue"> blue</label> </div> <div class="red box">You have selected <strong>red radio button</strong> so i am here</div> <div class="green box">You have selected <strong>green radio button</strong> so i am here</div> <div class="blue box">You have selected <strong>blue radio button</strong> so i am here</div> </body> </html> 

這是一個示例示例,您可以參考

暫無
暫無

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

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