$(document).ready(function(){
$('.select_one').change(function(){
var cli = $('.select_one').val();
if(cli != "0"){
$('.dis_one').val('');
$('.regain_one').val('0');
$('#key_one').attr('disabled',false);
$('.dis_one').attr('disabled',true);
$('.dis_one').attr('placeholder',"二级菜单已失效!");
}else{
$('#key_one').attr('disabled',true);
$('.dis_one').attr('disabled',false);
$('.dis_one').attr('placeholder',"二级菜单已生效!");
}
});
$('.select_two').change(function(){
var cli = $('.select_two').val();
if(cli != "0"){
$('.dis_two').val('');
$('.regain_two').val('0');
$('#key_two').attr('disabled',false);
$('.dis_two').attr('disabled',true);
$('.dis_two').attr('placeholder',"二级菜单已失效!");
}else{
$('#key_two').attr('disabled',true);
$('.dis_two').attr('disabled',false);
$('.dis_two').attr('placeholder',"二级菜单已生效!");
}
});
$('.select_three').change(function(){
var cli = $('.select_three').val();
if(cli != "0"){
$('.dis_three').val('');
$('.regain_three').val('0');
$('#key_three').attr('disabled',false);
$('.dis_three').attr('disabled',true);
$('.dis_three').attr('placeholder',"二级菜单已失效!");
}else{
$('#key_three').attr('disabled',true);
$('.dis_three').attr('disabled',false);
$('.dis_three').attr('placeholder',"二级菜单已生效!");
}
});
$('#create').click(function(){
var name_one = $('#name_one').val();
var name_one_one = $('#name_one_one').val();
var name_one_two = $('#name_one_two').val();
var name_one_three = $('#name_one_three').val();
var name_one_four = $('#name_one_four').val();
var name_one_five = $('#name_one_five').val();
var name_two = $('#name_two').val();
var name_two_one = $('#name_two_one').val();
var name_two_two = $('#name_two_two').val();
var name_two_three = $('#name_two_three').val();
var name_two_four = $('#name_two_four').val();
var name_two_five = $('#name_two_five').val();
var name_three = $('#name_three').val();
var name_three_one = $('#name_three_one').val();
var name_three_two = $('#name_three_two').val();
var name_three_three = $('#name_three_three').val();
var name_three_four = $('#name_three_four').val();
var name_three_five = $('#name_three_five').val();
var select_one = $('.select_one').val();
var select_one_one = $('.select_one_one').val();
var select_one_two = $('.select_one_two').val();
var select_one_three = $('.select_one_three').val();
var select_one_four = $('.select_one_four').val();
var select_one_five = $('.select_one_five').val();
var select_two = $('.select_two').val();
var select_two_one = $('.select_two_one').val();
var select_two_two = $('.select_two_two').val();
var select_two_three = $('.select_two_three').val();
var select_two_four = $('.select_two_four').val();
var select_two_five = $('.select_two_five').val();
var select_three = $('.select_three').val();
var select_three_one = $('.select_three_one').val();
var select_three_two = $('.select_three_two').val();
var select_three_three = $('.select_three_three').val();
var select_three_four = $('.select_three_four').val();
var select_three_five = $('.select_three_five').val();
var key_one = $('#key_one').val();
var key_one_one = $('#key_one_one').val();
var key_one_two = $('#key_one_two').val();
var key_one_three = $('#key_one_three').val();
var key_one_four = $('#key_one_four').val();
var key_one_five = $('#key_one_five').val();
var key_two = $('#key_two').val();
var key_two_one = $('#key_two_one').val();
var key_two_two = $('#key_two_two').val();
var key_two_three = $('#key_two_three').val();
var key_two_four = $('#key_two_four').val();
var key_two_five = $('#key_two_five').val();
var key_three = $('#key_three').val();
var key_three_one = $('#key_three_one').val();
var key_three_two = $('#key_three_two').val();
var key_three_three = $('#key_three_three').val();
var key_three_four = $('#key_three_four').val();
var key_three_five = $('#key_three_five').val();
var json = [];
json.push('{');
json.push('"button":[');
/* 菜单一 json begin*/
if(name_one != ""){
if (select_one != '0' && name_one != "") {
json.push('{"type":"'+select_one+'",');
json.push('"name":"'+name_one+'",');
if (select_one == 'click'){
json.push('"key":"'+key_one+'"}');
}
if (select_one == 'view') {
json.push('"url":"'+key_one+'"}');
}
if(name_two == "" && name_three == ""){
json.push(']');
}
}
if (select_one == '0' && name_one != ""){
json.push('{"name":"'+name_one+'",');
json.push('"sub_button":[');
if (select_one_one != '0') {
json.push('{"type":"'+select_one_one+'",');
json.push('"name":"'+name_one_one+'",');
if (select_one_one == 'click'){
json.push('"key":"'+key_one_one+'"}');
}
if (select_one_one == 'view') {
json.push('"url":"'+key_one_one+'"}');
}
}
if (select_one_two != '0') {
json.push(',{"type":"'+select_one_two+'",');
json.push('"name":"'+name_one_two+'",');
if (select_one_two == 'click'){
json.push('"key":"'+key_one_two+'"}');
}
if (select_one_two == 'view') {
json.push('"url":"'+key_one_two+'"}');
}
}
if (select_one_three != '0') {
json.push(',{"type":"'+select_one_three+'",');
json.push('"name":"'+name_one_three+'",');
if (select_one_three == 'click'){
json.push('"key":"'+key_one_three+'"}');
}
if (select_one_three == 'view') {
json.push('"url":"'+key_one_three+'"}');
}
}
if (select_one_four != '0') {
json.push(',{"type":"'+select_one_four+'",');
json.push('"name":"'+name_one_four+'",');
if (select_one_four == 'click'){
json.push('"key":"'+key_one_four+'"}');
}
if (select_one_four == 'view') {
json.push('"url":"'+key_one_four+'"}');
}
}
if (select_one_five != '0') {
json.push(',{"type":"'+select_one_five+'",');
json.push('"name":"'+name_one_five+'",');
if (select_one_five == 'click'){
json.push('"key":"'+key_one_five+'"}');
}
if (select_one_five == 'view') {
json.push('"url":"'+key_one_five+'"}');
}
}
json.push(']');
json.push('}');
}
}
/* 菜单一 json end*/
/* 菜单二 json begin*/
if(name_two != ""){
if (select_two != '0' && name_two != "") {
if (name_one != "") {
json.push(',');
}
json.push('{"type":"'+select_two+'",');
json.push('"name":"'+name_two+'",');
if (select_two == 'click'){
json.push('"key":"'+key_two+'"}');
}
if (select_two == 'view') {
json.push('"url":"'+key_two+'"}');
}
if(select_two == "0"){
json.push(']');
}
}
if(select_two == '0' && name_two != ""){
if (name_one != "") {
json.push(',');
}
json.push('{"name":"'+name_two+'",');
json.push('"sub_button":[');
if (select_two_one != '0') {
json.push('{"type":"'+select_two_one+'",');
json.push('"name":"'+name_two_one+'",');
if (select_two_one == 'click'){
json.push('"key":"'+key_two_one+'"}');
}
if (select_two_one == 'view') {
json.push('"url":"'+key_two_one+'"}');
}
}
if (select_two_two != '0') {
json.push(',{"type":"'+select_two_two+'",');
json.push('"name":"'+name_two_two+'",');
if (select_two_two == 'click'){
json.push('"key":"'+key_two_two+'"}');
}
if (select_two_two == 'view') {
json.push('"url":"'+key_two_two+'"}');
}
}
if (select_two_three != '0') {
json.push(',{"type":"'+select_two_three+'",');
json.push('"name":"'+name_two_three+'",');
if (select_two_three == 'click'){
json.push('"key":"'+key_two_three+'"}');
}
if (select_two_three == 'view') {
json.push('"url":"'+key_two_three+'"}');
}
}
if (select_two_four != '0') {
json.push(',{"type":"'+select_two_four+'",');
json.push('"name":"'+name_two_four+'",');
if (select_two_four == 'click'){
json.push('"key":"'+key_two_four+'"}');
}
if (select_two_four == 'view') {
json.push('"url":"'+key_two_four+'"}');
}
}
if (select_two_five != '0') {
json.push(',{"type":"'+select_two_five+'",');
json.push('"name":"'+name_two_five+'",');
if (select_two_five == 'click'){
json.push('"key":"'+key_two_five+'"}');
}
if (select_two_five == 'view') {
json.push('"url":"'+key_two_five+'"}');
}
}
json.push(']');
json.push('}');
}
}
/* 菜单二 json end*/
/* 菜单三 json begin*/
if(name_three != ""){
if (select_three != '0' && name_three != "") {
if (name_two != "" || name_one != "") {
json.push(',');
}
json.push('{"type":"'+select_three+'",');
json.push('"name":"'+name_three+'",');
if (select_three == 'click'){
json.push('"key":"'+key_three+'"}');
}
if (select_three == 'view') {
json.push('"url":"'+key_three+'"}');
}
if(select_three == "0"){
json.push(']');
}
}
if (select_three == '0' && name_three != "") {
if (name_two != "" || name_one != "") {
json.push(',');
}
json.push('{"name":"'+name_three+'",');
json.push('"sub_button":[');
if (select_three_one != '0') {
json.push('{"type":"'+select_three_one+'",');
json.push('"name":"'+name_three_one+'",');
if (select_three_one == 'click'){
json.push('"key":"'+key_three_one+'"}');
}
if (select_three_one == 'view') {
json.push('"url":"'+key_three_one+'"}');
}
}
if (select_three_two != '0') {
json.push(',{"type":"'+select_three_two+'",');
json.push('"name":"'+name_three_two+'",');
if (select_three_two == 'click'){
json.push('"key":"'+key_three_two+'"}');
}
if (select_three_two == 'view') {
json.push('"url":"'+key_three_two+'"}');
}
}
if (select_three_three != '0') {
json.push(',{"type":"'+select_three_three+'",');
json.push('"name":"'+name_three_three+'",');
if (select_three_three == 'click'){
json.push('"key":"'+key_three_three+'"}');
}
if (select_three_three == 'view') {
json.push('"url":"'+key_three_three+'"}');
}
}
if (select_three_four != '0') {
json.push(',{"type":"'+select_three_four+'",');
json.push('"name":"'+name_three_four+'",');
if (select_three_four == 'click'){
json.push('"key":"'+key_three_four+'"}');
}
if (select_three_four == 'view') {
json.push('"url":"'+key_three_four+'"}');
}
}
if (select_three_five != '0') {
json.push(',{"type":"'+select_three_five+'",');
json.push('"name":"'+name_three_five+'",');
if (select_three_five == 'click'){
json.push('"key":"'+key_three_five+'"}');
}
if (select_three_five == 'view') {
json.push('"url":"'+key_three_five+'"}');
}
}
json.push(']');
json.push('}');
}
}
/* 菜单三 json end*/
if(select_one == "0"){
json.push(']');
}
json.push('}');
var menu = json.join('');
var param = {"menu" : menu};
console.log(param);
var url = 'MenuManagerServlet';
$.post(url, {"menu" : menu}, function(data){
console.log(data);
});
});
});
欢迎指教,有更好的方法请评论谢谢!
微信自定义菜单开发json拼接
最新推荐文章于 2022-10-06 13:49:47 发布