0

大家好,我想知道是否可以通过javascript通过调用该css规则将通过css访问的.png转换为可点击的链接。

.calendar {
    background: transparent url("../cal_icon.png") no-repeat 94px 3px;
    background-repeat: no-repeat;
    margin-right: 2px;
}

这是我想让我的 cal_icon.png 可点击的 css 规则。这可能吗?请原谅我对这件事的无知。

4

1 回答 1

0

正如评论中所说,您需要向元素添加点击处理程序,而 css 仅用于样式

你可以看看这个小提琴,它使用 jQuery (onLoad) http://jsfiddle.net/tq92z/

$('.calendar').click(function(){
    $(this).css('color','red');
})

IE 有一个 css 表达式,也许其他浏览器有别的东西(但我现在什么都不记得了)

http://www.richnetapps.com/using_javascript_expressions_in_css/

但是用 css 进行 dom 操作并不是一种常见的做法

于 2013-01-04T00:10:23.447 回答