如何在点击时获得 css 悬停值? [英] How to get css hover values on click?

查看:20
本文介绍了如何在点击时获得 css 悬停值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

跟进这个 问题,我还有另一个问题 - 单击文本链接时如何获取 css 悬停值?

Following up on this question, I have another issue - how to get css hover values when you click on a text link?

例如,我有文本悬停的这些值

For instance, I have these values for the text hover

a.test {
    text-decoration:none;
}

a.test:hover {
    text-decoration:none;
    opacity:0.6 !important;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=60)"; 
    filter:alpha(opacity=60) !important; 
}

<a href="#" class="test">Click Me</a>

这当然失败了!

$(".test").click(function(){
   alert($(this).css());
   return false;
})

有可能吗?

我遇到了类似的问题,但我不想使用那个插件.

I came across this similar question but I prefer not to use that plugin.

推荐答案

你可以做这样的事情,你可以创建自己的 CSS 属性列表,这些属性将应用于该元素(假设你有一个列表),然后循环通过他们:

You could do something like this, where you create your own list of css properties that would be applied to that element (assuming you had a list) and then cycle through them:

var cssList = ['text-decoration','opacity','filter'];

$(".test").click(function(){
    for(x in cssList){
        alert($(this).css(cssList[x]));
    }    
   return false;
})

示例:http://jsfiddle.net/jasongennaro/GmWCz/

当然,如果你需要的话,你可以一直使用它并添加所有属性.

Of course, you could take this all the way and add all the properties, if that is what you needed.

这篇关于如何在点击时获得 css 悬停值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆