gpt4 book ai didi

javascript - 如何打印动态跨度类值?

转载 作者:行者123 更新时间:2023-11-30 14:56:18 25 4
gpt4 key购买 nike

我有一个动态出现的跨度类值。{{$school->name}}。问题是当我点击它时我可以看到警报值。但不是每次.什么可能是最佳解决方案..任何人都可以提出建议吗?

  <div class="dropdown_wrapper">
@foreach($schools as $school)
<li class="school" id="school1">
<span class="icon glyphicon glyphicon-education"></span>
<span class="school_title">{{$school->name}}</span>
</li>
@endforeach
</div>



$(".school_title").on("click", function (argument) {
var school = $(this).html();
alert(school);
});

最佳答案

如果我理解你的问题你正在寻找这种东西:-

 <div class="dropdown_wrapper">
@foreach($schools as $key => $school)
<li class="school" id="school1">
<span class="icon glyphicon glyphicon-education"></span>
<span id="{{$key}}" class="school_title">{{$school->name}}</span>
</li>
@endforeach
</div>



$(".school_title").on("click", function () {
var getid = $(this).attr('id');
var school = $("#"+getid).html();
alert(school);
});

希望对您有所帮助!

关于javascript - 如何打印动态跨度类值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47235067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com