gpt4 book ai didi

javascript - 如何在社交菜单栏中附加图标

转载 作者:行者123 更新时间:2023-11-27 23:50:21 24 4
gpt4 key购买 nike

我尝试将社交图标附加到下拉菜单栏,但我不知道为什么我的代码不起作用

有人可以帮助我吗?

<script>
$(document).ready(function(){

$("li.has-dropdown:eq(6) ul.dropdown li a").each(function(){
var thisText = $(this).text();

if( thisText=="Facebook"){
$(this).prepend("<i class="fa fa-facebook-square fa-2x"></i>");
};
if( thisText=="Twitter"){
$(this).prepend('<i class="fa fa-twitter-square fa-2x"></i>');
};
if( thisText=="Youtube"){
$(this).prepend('<i class="fa fa-youtube-square fa-2x"></i>');
};
if( thisText=="Googleplus"){
$(this).prepend('<i class="fa fa-google-plus-square fa-2x"></i>');
};
if( thisText=="Printerest"){
$(this).prepend('<i class="fa fa-pinterest-square fa-2x"></i>');
};
if( thisText=="Instagram"){
$(this).prepend('<i class="fa fa-instagram fa-2x"></i>');
};
});
});
</script>

谢谢大家,我瞄准了错误的下拉菜单。现在它可以工作了

最佳答案

您正在转义引号。

使用 prepend 时需要使用单引号,应用类元素时需要使用双引号 "

例如:

$(this).prepend('<i class="fa fa-facebook-square fa-2x"></i>');

http://jsfiddle.net/dsbx5b5g/1/

关于javascript - 如何在社交菜单栏中附加图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32768778/

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