我有2个图像作为一个按钮,它会改变人是否点击打开或关闭滑块,我也有stopPropagation事件关闭滑块,如果我点击div(滑块外的任何地方)切换滑块按钮图像回到正常
我现在想要的是让图像恢复正常(第一个图像显示为一个按钮),如果一个人在div外面点击,同样的方式,如果他们点击按钮再次关闭,因为如果通过单击按钮打开滑块,然后单击div外部以关闭它,则图像不会更改。这里是我的代码:http://jsfiddle.net/v0yfb72v/
jQquery:
$('#toggle-onoff-network').on({
'click': function() {
var origsrc = $(this).attr('src');
var src = '';
if (origsrc == 'http://www.pulseframe.com/images/Button-on.png') src = 'http://www.pulseframe.com/images/Button-off.png';
if (origsrc == 'http://www.pulseframe.com/images/Button-off.png') src = 'http://www.pulseframe.com/images/Button-on.png';
jQuery(this).attr('src', src);
}
});
// The script
$(document).ready(function(){
$('#netywork-toggle').click(function(event){
event.stopPropagation();
$("#voyaflex-container").slideToggle("fast");
});
$("#voyaflex-container").on("click", function (event) {
event.stopPropagation();
});
});
$(document).on("click", function() {
$("#voyaflex-container").hide();
});
这只是一个小问题...现在,滑块现在点击我在它外面点击任何地方 – 2014-10-30 18:31:25
我更新了我的答案。检查容器是否可见,如果是,则运行click事件。 – 2014-10-30 18:33:37
非常感谢,现在运行良好。 – 2014-10-30 18:34:57