Skip to main content
 首页 » 编程设计

jquery之通过单击事件更改所有元素的样式

2026年07月24日1022zhwl

我正在学习 JQuery,因为我正在对网站进行重大重新设计。我意识到在 javascript 中做一些样式设置而不是记住向每个 div 添加正确的 css 类是多么美好(显然,我喜欢忘记这些事情)。

无论如何,我想将样式 cursor:pointer; 添加到所有注册了单击事件的元素。我认为它需要看起来像这样:

$("div").Find(/*Has Click Event*/) 
  .css("cursor", "pointer"); 

请您参考如下方法:

$("div").each(function () { 
    if($(this).data("events") !== 'undefined' && $(this).data("events").click) { 
        $(this).css({"cursor": "pointer", "border": "1px solid red"}); 
    } 
});​ 

Demo.