家
我正在尝试使用 onClick 更改主页链接的背景图像和字体颜色。但我无法达到结果。有人可以帮忙吗?
例子:
<script type="text/javascript">
function change(element)
{
element.style.backgroundImage = "url('http://blog.grio.com/wp-content/uploads/2012/09/stackoverflow.png')";
element.style.color = '#E61E1E';
}
</script>
<div onclick="change(this)" style="width: 128px; height:128px; cursor: pointer;">
test test test ...
</div>
或者:
<div onclick="this.style.backgroundImage = 'url(\'http://blog.grio.com/wp-content/uploads/2012/09/stackoverflow.png\')';this.style.color = '#E61E1E';" style="width: 128px; height:128px; cursor: pointer;">
test test test ...
</div>