本文介绍了onClick与foreach css更改jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 foreach
循环在php与bootstrap崩溃面板,我想知道是否有任何选项改变颜色 div.panel
I have a foreach
loop in php with bootstrap collapse panel and I want to know if there is any option to change color of div.panel-heading
on-click for a single title.
因此,当我点击< a href的第一个标题时=...>< / a>
只有第一个 div.panel标题
变成红色背景。
So when I click on first title of <a href="..."></a>
only the first div.panel-heading
turns into red background.
@foreach($aa as $msg)
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
Sender: <a href="/member-list/{{{$msg->username}}}">{{{$msg->username}}}</a>
{{{ " title: ". " "}}}
<a data-toggle="collapse" data-parent="#accordion" href="#collapse{{{$msg->msg_id}}} ">
{{{$msg->title}}}
</a>
</h4>
</div>
<div id="collapse{{{$msg->msg_id}}}" class="panel-collapse collapse">
<div class="panel-body">
{{{$msg->msg}}}
</div>
</div>
</div>
@endforeach
推荐答案
jquery:
$('div.panel-heading a').click(function(){
$('div.panel-heading').css('background','transparent');
var ParentDiv = $(this).parent();
ParentDiv.css('background','red');
});
这篇关于onClick与foreach css更改jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!