我有一个脚本,它显示一个隐藏在一个 li 中的 div,但目前它只显示第一个 li 的 div,脚本在另一个 li 上添加“selected”类,但显示第一个 li 的 div。
这是我的代码
$(document).on("pageinit", function(e){
$(".menu_slide").click(function(event) {
$(this).parents('li').addClass('selected');
var sm = $($("#"+ $(e.target).attr('id') +" :jqmData(slidemenu)").data('slidemenu'));
var sa = $('li.selected').attr('class');
// console.log(sm);
if($("li").hasClass("selected")){
$(document).on("click", ":jqmData(slidemenu)", function(e) {
// console.log(sm.data('slideopen'));
slidemenu(sm, sm.data('slideopen'));
e.stopImmediatePropagation();
e.preventDefault();
}); sta
} else {
// Todo code
}
});
});
function slidemenu(sm, only_close) {
if (!sm.data('slideopen') && !only_close) {
var swipe = $('.menu_slide_swipe');
var wi = $(window).width();
// Portrait Phone
if(wi == 320){
sm.show().animate({ left:'31px', avoidTransforms: true, useTranslate3d: true}, 'fast');
swipe.show().animate({ left:'6px', avoidTransforms: true, useTranslate3d: true}, 'fast');
sm.data('slideopen', true);
}
// Landscape Phone
if (wi == 569){
sm.show().animate({ left:'307px', avoidTransforms: true, useTranslate3d: true}, 'fast');
swipe.show().animate({ left:'281px', avoidTransforms: true, useTranslate3d: true}, 'fast');
sm.data('slideopen', true);
}
// Portrait Tablet
if(wi == 769){
sm.show().animate({width:'450px', left:'302px', avoidTransforms: true, useTranslate3d: true}, 'fast');
swipe.show().animate({ left:'276px', avoidTransforms: true, useTranslate3d: true}, 'fast');
sm.data('slideopen', true);
}
// Landscape Tablet
if(wi == 1024){
sm.show().animate({width:'450px', left:'552px', avoidTransforms: true, useTranslate3d: true}, 'fast');
swipe.show().animate({ left:'525px', avoidTransforms: true, useTranslate3d: true}, 'fast');
sm.data('slideopen', true);
}
if ($(":jqmData(role='header')").data('position') == 'fixed') {
} else {
$(":jqmData(slidemenu)").css('margin-left', '10px');
}
} else {
var swipe = $('.menu_slide_swipe');
sm.animate({left:'-260px', avoidTransforms: false, useTranslate3d: true}, 'fast', function(){sm.hide()});
swipe.animate({left:'-60px', avoidTransforms: false, useTranslate3d: true}, 'fast', function(){swipe.hide()});
sm.data('slideopen', false);
$(":jqmData(slidemenu)").css('margin-left', '0px');
$("li.ui-li").removeClass("selected");
}
return false;
}
编辑
$(".menu_slide").click(function (event) {
$(this).parents('li').addClass('selected');
var sm = $($("#" + $(e.target).attr('id') + " :jqmData(slidemenu)").data('slidemenu'));
var sa = $('li.selected').attr('class');
});
$(document).on("click", "li.selected :jqmData(slidemenu)", function (e) {
var sm = $($("#" + $(e.target).attr('id') + " :jqmData(slidemenu)").data('slidemenu'));
slidemenu(sm, sm.data('slideopen'));
e.stopImmediatePropagation();
e.preventDefault();
});