在这里快速提问,我似乎无法得到这个
$('#wrap').on('toggle', '#image', function(){
<!-- Do stuff -->
});
Run Code Online (Sandbox Code Playgroud)
能够在里面切换?有任何想法吗?我试过谷歌搜索但没有运气.
这是我试图与.on一起工作的代码,因为目前它没有将更改应用于页面的所有元素,(有#image和#brick)
$("#result_options").toggle(function() {
var image_width = $('#image').width() / 2;
var brick_width = $('#brick').width() / 2;
$("#image").css("width",image_width);
$("#image").css("padding","4px");
$("#brick").css("width",brick_width);
},function (){
$("#image").css("width","300");
$("#image").css("padding","8px");
$("#brick").css("width","314");
$(this).html("Smaller Results");
});
});
Run Code Online (Sandbox Code Playgroud)
Dav*_*mas 24
你面临的问题是没有toggle事件; toggle()是一个jQuery方法.要实现一个toggle(),on()我认为你需要使用一个click事件,然后一个if语句来测试是否已经切换了某些内容,或者是否切换了切换/未切换
$('#wrap').on('click', '#image', function(){
if (!$(this).attr('data-toggled') || $(this).attr('data-toggled') == 'off'){
/* currently it's not been toggled, or it's been toggled to the 'off' state,
so now toggle to the 'on' state: */
$(this).attr('data-toggled','on');
// and do something...
}
else if ($(this).attr('data-toggled') == 'on'){
/* currently it has been toggled, and toggled to the 'on' state,
so now turn off: */
$(this).attr('data-toggled','off');
// and do, or undo, something...
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14809 次 |
| 最近记录: |