进制转换方法:string.toString(number)//number为要转换的进制数
eg:
var a = parseInt(125).toString(10);
console.log(a);//7d
应用:rgb转换成‘#000’格式:
eg:
var rgbString = $('header').css('backgroundColor'); // get this in whatever way.
var parts = rgbString.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
console.log(parts)
delete (parts[0]);
for (var i = 1; i <= 3; ++i) {
parts[i] = parseInt(parts[i]).toString(16);
if (parts[i].length == 1){
parts[i] = '0' + parts[i];
}
}
var hexString = '#' + parts.join(''); // "#0070ff"
console.log(hexString)
类名:
为 <div> 元素添加 class:
document.getElementById("D").classList.add("m");
为 <div> 元素添加多个类:
document.getElementById("D").classList.add("m", "an", "thi");
为 <div> 元素移除一个类:
document.getElementById("D").classList.remove("m");
为 <div> 元素移除多个类:
document.getElementById("D").classList.remove("m", "an", "thi");
检查是否含有某个CSS类
myDiv.classList.contains('myC'); //return true or false