H5 自定義選項(xiàng)卡(兩級(jí)菜單聯(lián)動(dòng))

最近在寫html,寫了一個(gè)自定義選項(xiàng)卡,兩級(jí)菜單聯(lián)動(dòng),作為初學(xué)者,代碼比較亂,句釋什么的沒怎么仔細(xì)寫,大家將就看吧:( 簡(jiǎn)書不支持html標(biāo)簽編輯@ ~ @)

樣式:

*{padding: 0;margin: 0;}

body{

background-color:#D3D3D3;

}

.top,.top_menu{

background-color:white ;

color: black;

padding:10px 10px 15px;

margin:15px 5px;

}

.middle{

display: none;

background-color:white ;

color: black;

margin:15px 5px;

padding:5px 15px? 20px;

}

.money button,.top_menu button{

margin: 10px 0.8%;

width: 22%;

height: 30px;

background-color: white;

border: 1px solid lightgrey;

}

.middleDetail{

width: 30px;

margin: 10px 20%;

}

#pointOut{

color: darkorange;

padding: 15px;

}

#bottom{

width: 50%;

height: 50px;

margin:0 20%;

background-color: orange;

font-size:20px ;

color: white;

}

.money .active{

color: orange;

border: 1px solid orange;

background-color: white;

}

.middie_menu li{

list-style-type: none;

}

.money_input{

/*background-color: red;*/

margin: 10px;

text-align: center;

}

.money_input input{

width: 50%;

/*background-color: blue;*/

margin: 5px;

text-align: center;

line-height: 20px;

}

.hidden{

display: none;

}

body:簡(jiǎn)書不支持html,就用圖片代替了~~





javaScript:

var index=0;

var money=0;

var chargeWayIndex=0;

$(document).ready(function()

{

//點(diǎn)擊確定按鈕,獲取菜單參數(shù)

$("#bottom").click(function()

{

var y =? $(".menu_btn");

console.log($(".menu_btn"));

console.log($(".btn .active"));

console.log(y[chargeWayIndex]);

var btn = y[chargeWayIndex];

console.log(btn.innerHTML);

var x = $(".btn");

console.log(x);

console.log("index:"+index);

console.log("chargeWayIndex:"+chargeWayIndex);

console.log(x[index]);

var indexy = index + chargeWayIndex*4;

console.log(indexy);

var xhtml = x[indexy].innerHTML;

console.log(xhtml);

console.log(xhtml.substring(0,xhtml.length-1));

});

// 二級(jí)菜單點(diǎn)擊事件

$(".btn").on("click",function(){

$(this).addClass("active").siblings().removeClass("active");

var sbtitle=$(".middle");

if($(this).index() == "3"){//判斷是否點(diǎn)擊了自定義

if(sbtitle.length){

sbtitle.show();

}

}else{

sbtitle.hide();

}

index = $(this).index();

});

});

//以及菜單點(diǎn)擊事件

$(".menu_btn").on("click",function(){

$(this).addClass("active").siblings().removeClass("active");

var sbtitle=$(".top");

chargeWayIndex? = $(this).index();

//alert(chargeWayIndex);

// $(".btn").removeClass("active");

showtopmenu(chargeWayIndex);

});

//改變?nèi)?jí)菜單自定義選項(xiàng)卡

function showtopmenu(i){

//以下三行代碼不能少,會(huì)出現(xiàn)BUG

$(".top").hide();

$(".middle").hide();

$(".btn").removeClass("active");

switch(i){

case 0:

//alert("電量");

var visible = $("#chagerWay1");

visible.show();

// document.getElementsByClassName("middleTitle").innerHTML = "自定義充電金額";

$(".middleTitle").html("自定義充電金額");

$("#middle_input_span").html("元");

break;

case 1:

//alert("時(shí)間");

// $("middleTitle").innerText="自定義充電時(shí)長(zhǎng)";

var visible = $("#chagerWay2");

visible.show();

// document.getElementsByClassName("middleTitle").val = "自定義充電時(shí)長(zhǎng)";

var a = document.getElementById("middleTitle");

$(".middleTitle").html("自定義充電時(shí)長(zhǎng)");

$("#middle_input_span").html("小時(shí)");

break;

case 2:

//alert("電量");

var visible = $("#chagerWay3");

visible.show();

// document.getElementsByClassName("middleTitle").innerHTML = "自定義充電電量";

$(".middleTitle").html("自定義充電電量");

$("#middle_input_span").html("度");

break;

default:

//alert("充滿");

var visible = $("#chagerWay4");

visible.show();

var sbtitle=$(".middle");

sbtitle.hide();

break;

}

}

效果圖:




最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容