您好我正在尝试使用 jquery 进行三态翻转。我想要一个开启状态关闭状态和点击状态。
我必须复制特定的界面样式,而不是使用图片。下面是我使用的代码。但是,我似乎无法弄清楚单击另一个图像时如何停用图像。
这是一个场景。
1) 用户将鼠标悬停在激活开启状态图像的图像上。2) 用户从该图像移到另一个图像。先前的活动图像关闭,当前悬停的图像打开。3) 用户单击激活单击状态图像的图像,但是,当用户单击另一个图像时,先前单击的图像返回关闭状态。
我可以使用 Javascript 来做到这一点,但是,我是 Jquery 的新手,很难弄清楚这一点。
这是代码:
$(document).ready(function() {
// Navigation rollovers
$("#nav a").mouseover(function(){
imgsrc = $(this).children("img").attr("src");
matches = imgsrc.match(/_on/);
// don't do the rollover if state is already ON
if (!matches) {
imgsrcON = imgsrc.replace(/.gif$/ig,"_on.gif");
// strip off extension
$(this).children("img").attr("src", imgsrcON);
}
});
$("#nav a").mouseout(function(){
$(this).children("img").attr("src", imgsrc);
});
// Navigation clicks
$("#nav a").click(function(){
imgsrc = $(this).children("img").attr("src");
clkmatches = imgsrc.match(/_on/);
// don't do the rollover if state is already ON
if (!clkmatches) {
imgsrcCLK = imgsrc.replace(/.gif$/ig,"_clk.gif");
// strip off extension
$(this).attr("src", imgsrcCLK);
}
});
});