Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

jquery - 使用jQuery切换DIV背景图像(Switching a DIV background image with jQuery)

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.

(按钮上的文字是背景图像。)

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

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

  ask by zuk1 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
$('#divID').css("background-image", "url(/myimage.jpg)");  

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

(应该可以解决问题,只需将其挂接到元素的click事件中即可)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...