使用jQuery切换DIV背景图像 [英] Switching a DIV background image with jQuery

查看:77
本文介绍了使用jQuery切换DIV背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我工​​作的公司制作一个扩展/折叠通话费率表.我目前有一个桌子,下面有个按钮来展开它,该按钮说展开".除了我需要在单击按钮时将按钮更改为折叠",然后在再次单击按钮时将其更改为展开"之外,此功能正常.按钮上的文字是背景图片.

I am making an expand/collapse call rates table for the company I work for. I currently have a table with a button under it to expand it, the button says "Expand". It is functional except I need the button to change to "Collapse" when it is clicked and then of course back to "Expand" when it is clicked again. The writing on the button is a background image.

因此,基本上,我需要做的就是在单击div时更改div的背景图像,除了像切换一样.

So basically all I need is to change the background image of a div when it is clicked, except sort of like a toggle.

推荐答案

$('#divID').css("background-image", "url(/myimage.jpg)");  

应该做到这一点,只需将其挂接到元素上的click事件中

Should do the trick, just hook it up in a click event on the element

$('#divID').click(function()
{
  // do my image switching logic here.
});

这篇关于使用jQuery切换DIV背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆