Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 字母化身-如何为每组字母添加不同的颜色类别-A到H,J到S,T到Z?_Jquery_Html_Css - Fatal编程技术网

Jquery 字母化身-如何为每组字母添加不同的颜色类别-A到H,J到S,T到Z?

Jquery 字母化身-如何为每组字母添加不同的颜色类别-A到H,J到S,T到Z?,jquery,html,css,Jquery,Html,Css,我想为我的字母“阿凡达”分别添加颜色类别——徽章绿、徽章金、徽章蓝——A到H、J到S、T到Z(就像在Gmail中一样)。 如果您感兴趣,我已经创建了一个php函数: 函数randomHex(){ $chars='77B5FE';//ABCDEF0123456789 $color='#'; 对于($i=0;$i

我想为我的字母“阿凡达”分别添加颜色类别——徽章绿、徽章金、徽章蓝——A到H、J到S、T到Z(就像在Gmail中一样)。


如果您感兴趣,我已经创建了一个php函数:

函数randomHex(){
$chars='77B5FE';//ABCDEF0123456789
$color='#';
对于($i=0;$i<6;$i++){
$color.=$chars[rand(0,strlen$chars)-1];
}
返回$color;
}
瞧

var firstName=$('.firstName').text();
变量nameintals=$('.firstName').text().charAt(0)/*+$('#lastName').text().charAt(0)*/;
$('.profileImage')。每个(函数(){
var profileInitial=$(this).sibbines('.firstName').text().charAt(0.toUpperCase();
$(this).text(profileInitial);

var avatarClass=profileInitial,但jquery解决方案会非常有用。无论如何,感谢您的努力。JS中的相同函数:
函数getRandomColor(){var length=6;var chars='0123456789ABCDEF';var hex='#';while(length--)hex+=chars[(Math.random()*16)| 0];return hex;}document write(getRandomColor());
var firstName = $('.firstName').text();
    var nameIntials = $('.firstName').text().charAt(0) /*+ $('#lastName').text().charAt(0)*/;
    $('.profileImage').each(function(){
        var profileImage = $(this).siblings('.firstName').text().charAt(0);
        $(this).text( profileImage );        
    });