在 Laravel 上使用 Jquery 和 Ajax 检查单选按钮时填充的下拉列表

你好朋友,当我想基于选中的单选按钮创建下拉菜单时,我遇到了问题,没有错误,这里什么也没有发生,我的代码有什么问题?


这是代码


<fieldset class="form-group">

                    <div class="row">

                        <label>Jenis Kegiatan : </label>

                      <div class="col-sm-10">


                        <?php $no=1; ?>

                        @foreach ($jkData as $jk => $val)

                        <div class="form-check">

                        <input class="form-check-input" type="radio" name="jk_id" id="jk_id{{$no++}}" value="{{$jk}}">

                        <label class="form-check-label" for="jk_id{{$no++}}">

                            {{$val}}

                          </label>

                        </div>

                        @endforeach

                      </div>

                    </div>

                  </fieldset>

                <div class="form-group">

                    <label>Komponen Kegiatan : </label>

                    <select class="form-control select2bs4 " name="kk_id" id="kk_id" style="width: 100%;">

                        <option disabled="true" selected="true">--- Komponen Kegiatan ---</option>

                    </select>

                </div>



蝴蝶不菲
浏览 97回答 1
1回答

慕雪6442864

您没有在 onchange 功能中使用正确的输入收音机。这select[name="jk_id"]:checked -syntax是不正确的将您的代码更改jQuery为下面的代码,它应该可以工作。jQuery(document).ready(function() {&nbsp; jQuery('input[type=radio]').on('change', function() {&nbsp; &nbsp; var jk = jQuery(this).val();&nbsp; &nbsp; if (jk) {&nbsp; &nbsp; &nbsp; jQuery.ajax({&nbsp; &nbsp; &nbsp; &nbsp; url: 'pengajuan/getKK/' + jk,&nbsp; &nbsp; &nbsp; &nbsp; type: "GET",&nbsp; &nbsp; &nbsp; &nbsp; dataType: "json",&nbsp; &nbsp; &nbsp; &nbsp; success: function(data) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(data);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery('select[name="kk_id"]').empty();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery.each(data, function(key, value) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('select[name="kk_id"]').append('<option value="' +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key + '">' + value + '</option>');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; $('select[name="kk_id"]').empty();&nbsp; &nbsp; }&nbsp; });});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript