从CSS调用JavaScript函数 [英] Call a javascript function from CSS

查看:38
本文介绍了从CSS调用JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道它是否有可能以下列方式实现:

I would like to know if its possible in any way to:

.button{
width: somePX;
height: somePX;
}

.button:hover
 {
  onmouseup = "func(".button")";
 }

或类似的东西.我认为这会很酷吗?而不是为每个按钮编写onmouseup = onmouseup = onmouseup = onmouseup = onmouseup = .....

or something like that. I think it would be kinda cool? instead of writing for each button onmouseup = onmouseup = onmouseup = onmouseup = onmouseup =.....

推荐答案

使用jQuery,您可以执行以下操作:

With jQuery, you could do something like:

$('.button').on('mouseup',function(){...});

CSS是一种样式语言,因此您不能使用它来修改HTML元素的行为,只能修改它们的样式.如果您希望修改行为,则可以使用JavaScript.

CSS is a styling language, so you cannot modify the behaviour of HTML elements with it, only their style. If you wish to modify the behaviour, you can use JavaScript.

您还可以使用Angular.js类指令通过 .button 类来更改所有元素的行为.但是,这又是一个JS库,而不是CSS.

You could also use an Angular.js Class directive to change the behaviour of all elements with the .button class. But again, this is a JS library and not CSS.

这篇关于从CSS调用JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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