判断颜色,改变颜色,点击恢复颜色
<script type="text/javascript">
$('#id-flag').click(function(){
var color = $(this).css("color");
var colorHex = (rgb2hex(color));
if(colorHex=="#808080")
$(this).css("color","#4CAE4C");
else
$(this).css("color","grey");
});
function rgb2hex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
</script>