4

有没有办法可以使用 JQuery 的 .css() 方法来提供以下光标样式?:

cursor: url(http://www.google.com/intl/en_ALL/mapfiles/closedhand.cur), default !important;
4

2 回答 2

6

jQuery 不理解!important,所以如果你删除它,它会起作用:

$('selector').css({
    'cursor': 'url(http://www.google.com/intl/en_ALL/mapfiles/closedhand.cur), default'}); 

有办法绕过它,为什么不使用 CSS 类呢?

/* CSS */
.cursor {
    cursor: url('http://www.google.com/intl/en_ALL/mapfiles/closedhand.cur'), default !important;
}

所以你可以:

$('selector').addClass('cursor');

还有其他选择,请参阅:如何使用 .css() 应用 !important?

于 2013-03-18T23:44:27.507 回答
1

使用下面的代码对我来说似乎工作正常,但是如上所述,我删除!important了使它工作的。

$('#cursor').css(        
    'cursor','url(http://www.google.com/intl/en_ALL/mapfiles/closedhand.cur),default'
);
于 2013-03-18T23:44:18.400 回答