我是新来的,但是,必须有一个更好的书写方式。如何简化/优化这个jQuery
三个相似的功能,它们可以与逗号或其他东西结合使用。
$('#open-sidebar').click(function(){
$("body").toggleClass("menu-active");
return false;
});
$('#close-sidebar').click(function(){
$("body").toggleClass("menu-active");
return false;
});
$("#top").bind("swiperight", function (e) {
$("body").toggleClass("menu-active");
return false;
});
$("#content").bind("swiperight", function (e) {
$("body").toggleClass("menu-active");
return false;
});
$("#top").bind("swipeleft", function (e) {
$("body").toggleClass("menu-active");
return false;
});
$("#content").bind("swipeleft", function (e) {
$("body").toggleClass("menu-active");
return false;
});
$("#navigation").bind("swipeleft", function (e) {
$("body").toggleClass("menu-active");
return false;
});
谢谢
一个你应该问这在http://代码审查。 stackexchange.com/。 – putvande