所以我有一些按钮,可以切换相同的引导程序模式。
我想要实现的是,当我单击模式内的 Edit toggler 按钮时,例如说切换按钮的背景会变成红色。>
因此,如果显示模式2 对其进行了切换,则通过点击编辑切换器,显示模式2 的背景将变为红色。>
或者如果是显示模式3 切换了模式,则背景会发生变化,依此类推
谢谢您的帮助!
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<script type="text/javascript" src="toplist.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<button type="button" id="toggler1" class="btn btn-primary toggler" data-toggle="modal" data-target="#exampleModal">
Show modal 1
</button>
<button type="button" id="toggler2" class="btn btn-primary toggler" data-toggle="modal" data-target="#exampleModal">
Show modal 2
</button>
<button type="button" id="toggler3" class="btn btn-primary toggler" data-toggle="modal" data-target="#exampleModal">
Show modal 3
</button>
<button type="button" id="toggler4" class="btn btn-primary toggler" data-toggle="modal" data-target="#exampleModal">
Show modal 4
</button>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
This is a modal
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" id="edit" class="btn btn-primary">Edit toggler</button>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
例如,您应该向按钮添加唯一标识符。 #id =“ edit-toggler” ...然后只需:
$("#edit-toggler").on('click', function(){
$('#show-modal-2').toggleClass("red");
});
Css:
.red{
background-color: red
}
我建议采用这种方法,它更易于修改和维护。将CSS属性和值硬编码到Jquery中不是很有用:)