问题描述
我想知道它是否有可能以下列方式实现:
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函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!