有没有办法切换.append()jQuery方法?(Is there a way to toggle the .append() jQuery method?)

编程入门 行业动态 更新时间:2024-10-27 21:25:26
没有办法切换.append()jQuery方法?(Is there a way to toggle the .append() jQuery method?)

我想追加另一个img来代替plus.svg。 如果你们知道以某种方式切换.append()方法的方法,那就太好了。 我想在你点击它时更改CSS,然后基本上再次更改它。

$(function(){ $("#btw").click(function(){ $("#btwl").slideToggle(300); $(this).append("<style>#btw::before{content: url(minus.svg);width: 16px;eight: 16px;background-size: 16px 16px;background-repeat: no-repeat;vertical-align: middle;padding-right: 10px;}</style>"); }); });

I want to appendToggle another img in place of plus.svg. If you guys know a way to somehow toggle the .append() method, that would be great. I want to change the CSS when you click on it, then change it again, basically.

$(function(){ $("#btw").click(function(){ $("#btwl").slideToggle(300); $(this).append("<style>#btw::before{content: url(minus.svg);width: 16px;eight: 16px;background-size: 16px 16px;background-repeat: no-repeat;vertical-align: middle;padding-right: 10px;}</style>"); }); });

最满意答案

如果使用toggleClass可以达到相同的效果:

$(this).toggleClass('selected');

然后在CSS样式表中执行以下操作:

.selected::before { content: url(minus.svg); width: 16px; height: 16px; background-size: 16px 16px; background-repeat: no-repeat; vertical-align: middle; padding-right: 10px; }

资料来源: http : //api.jquery.com/toggleClass/

You could achieve the same effect if you use toggleClass:

$(this).toggleClass('selected');

Then in your CSS stylesheet do something like:

.selected::before { content: url(minus.svg); width: 16px; height: 16px; background-size: 16px 16px; background-repeat: no-repeat; vertical-align: middle; padding-right: 10px; }

Source: http://api.jquery.com/toggleClass/

更多推荐

本文发布于:2023-08-02 20:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1381548.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有办法   方法   append   jQuery   toggle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!