douyun8885 2018-05-15 20:13
浏览 32
已采纳

您是否知道如何使用单击的城市值更改ID为“#showCities”的链接的值?

I have a link "All Country" that opens a modal with some cities:

<a class="city" id="showCities" data-toggle="modal" data-target="#modal2" href="">All Country</a>

In this modal are listed the cities that exist for all conferences stored in database. For example, if there are 2 conferences in the database and one conference has the city Newcastle and another conference has the city Leeds it shows in this modal Newcastle and Leeds.

<ul class="modal-list">
    @foreach($cities as $city)
        <li class="col-lg-4 col-md-6 col-sm-12">
            <a  class="" name="city" id="{{$city}}">{{$city}}</a>
        </li>
    @endforeach
</ul>

When the user click on some city I want to show the conferences that have the column "city" equal to the clicked city in the #conconferes div. And its working fine.

There is only one issue when the user click in a city in the modal it works, the modal is hidden and the appropriate conferences appear. But the link All Country instead of "All Country" should appear the name of the clicked city, for example "Newcastle". Do you know how to properly achieve that?

jquery:

$("a[name='city']").on('click', function(){


    var city = $(this).attr("id");


    $.ajax({

        url: '{{ route('city.conferences',null) }}/' + city,
        type: 'GET',
        success:function(result){
            console.log(result)

            alert(result);
            $('#conferences').empty();
            var newConferences='';
            var placeholder = "{{route('conferences.show', ['id' => '1', 'slug' => 'demo-slug'])}}";
            $.each(result, function(index, conference) {
                $('#modal2').modal('hide');
                var url = placeholder.replace(1, conference.id).replace('demo-slug', conference.slug);

                newConferences += '<div class="col-12 col-sm-6 col-lg-4 col-xl-3 mb-4">
' +
                '                        <div class="card box-shaddow">
' +
                '                            <img class="card-img-top" src='+ conference.image +' alt="Card image cap">
' +
                '                            <div class="card-body">
' +
                '                                <p class="font-size-sm"><i class="fa fa-calendar" aria-hidden="true"></i>  '+conference.start_date+'</p>
' +
                '                                <h5 class="card-title h6 font-weight-bold text-heading-blue">'+conference.name+'</h5>
' +
                '                                <p class="card-text font-size-sm"><i class="fa fa-map-marker" aria-hidden="true"></i> '+conference.place+', '+conference.city+'</p>
' +
                '                            </div>
' +
                '                           <div class="card-footer d-flex justify-content-between align-items-center">
' +
                '                                 <a href="' + url + '" class="btn btn-primary text-white">More</a>' +
                ' <span class="font-weight-bold font-size-sm"></span>
'
            '                           </div>
' +
            '                    </div>';
            });

            $('#conferences').html(newConferences);

        },
        error: function(error) {

            console.log(error.status)
        }

    });

});
  • 写回答

1条回答 默认 最新

  • douzi7890 2018-05-15 20:48
    关注

    This will take the text from the link of your list and replace the text for the showCities link upen a click on any link in your list.

    <script>
        $('a[name="city"]').on('click', function(){
            $('#showCities').text($(this).text());
        };
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器