好的,这听起来很简单,使用jquery的'click‘函数。
问题是,我想要的是原来的颜色链接,而不是它的悬停颜色-例如,如果链接是绿色与橙色的悬停状态,我要抓住绿色的颜色。
我已经尽了最大努力,并在小提琴中展示了它
有人有什么想法吗?
编辑:道歉,但许多鹰眼发现(感谢他们指出)绿色实际上是"rgb(0,128,0)",而不是rgb(0,255,0),如我最初的小提琴所示。
发布于 2012-08-31 14:14:28
将其存储在data对象中:
$('a').each(function() {
$(this).data('color', $(this).css('color') );
})
.click(function() {
alert( $(this).data('color') );
});这是你的小提琴:http://jsfiddle.net/sVDYe/4/
为了获得更好的性能,我会在循环中使用静态方法。他们要快得多
$('a').each(function() {
$.data(this, 'color', $.css(this, 'color') );
});这是小提琴:http://jsfiddle.net/sVDYe/13/
发布于 2012-08-31 14:21:23
试试下面的方法..。
演示:http://jsfiddle.net/sVDYe/33/
$("a").click(function(e) {
e.preventDefault();
var tmpLink =$(this).clone();
tmpLink.appendTo($(this).parent());
var acolor = tmpLink.css("color");
tmpLink.remove();
if (acolor == 'rgb(255, 165, 0)') {
alert('wrong color - its ORANGE =' + acolor);
} else if (acolor == 'rgb(0, 128, 0)') {
alert('CORRECT color - its GREEN =' + acolor);
}
});正如pimvdb所指出的..。绿色是RGB(0,128,0)
发布于 2012-08-31 14:22:26
试着像这样
http://jsfiddle.net/dadviegas/hfHBh/
https://stackoverflow.com/questions/12217098
复制相似问题