有没有办法切换.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/
更多推荐
发布评论