Есть табы, которые скрыты, при клике по элементу с нужным атрибутом, таб появляется. Как такой код, можно сократить? Причём, чем короче получится, тем лучше.
$(document).ready(function() {
$(".style_of_tabs").hide();
});
$(document).on('click', '.tab_add', function (){
var post = {};
post.ajaxRequest = true;
$metod = $(this).data('metod');
if($metod == 'country'){
$('#country').show();
post.country = true;
}
if($metod == 'currenci'){
$('#currenci').show();
post.currenci = true;
}
if($metod == 'package'){
$('#package').show();
post.package = true;
}
if($metod == 'activitidirection'){
$('#activitidirection').show();
post.activitidirection = true;
}
if($metod == 'branch'){
$('#branch').show();
post.branch = true;
}
if($metod == 'industrialdirection'){
$('#industrialdirection').show();
post.industrialdirection = true;
}
if($metod == 'measuri'){
$('#measuri').show();
post.measuri = true;
}
if($metod == 'fo'){
$('#fo').show();
post.fo = true;
}
if($metod == 'region'){
$('#region').show();
post.region = true;
}
if($metod == 'logistic'){
$('#logistic').show();
post.logistic = true;
}
if($metod == 'quality'){
$('#quality').show();
post.quality = true;
}
$(this).hide();
console.log(post);
var result = sendAjaxRequest({
url: '/infobase/getTabs',
data: post
});
});
$(document).ready(function() {
$(".style_of_tabs").hide();
});
$(document).on('click', '.tab_add', function (){
var post = {
ajaxRequest: true
};
var $method = $(this).data('method');
// >>> доступные методы
var methods = ['country', 'currenci', 'package', 'activitidirection', 'branc', 'industrialdirection', 'measuri'];
// >>> проверка, что метод в списке доступных
if (methods.indexOf($method) < 0) {
console.warn('method not allowed');
return;
}
// только в том случае, если имена совпадают
$('#' + $method).show();
post[$method] = true;
$(this).hide();
console.log(post);
var result = sendAjaxRequest({
url: '/infobase/getTabs',
data: post
});
});
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости