Я хотел бы упростить мой код в одну целую функцию. Поскольку он имеет те же атрибуты и функции, я не знаю, что именно функция вызова объединяет все это в одном действии.
$('a[data-user="add"]').click(function(event) {
event.preventDefault();
$('.list-unstyled li').removeClass('active');
$('section.col-lg-8').replaceWith(formAdd);
$('.form-custom').load('includes/pages/admin/admin-user-add.php');
subHash = this.hash;
});
$('a[data-user="settings"]').click(function(event) {
event.preventDefault();
$('.list-unstyled li').removeClass('active');
$('section.col-lg-8').replaceWith(formAdd);
$('.form-custom').load('includes/pages/admin/admin-user-settings.php');
subHash = this.hash;
});
Я подумал, что в том числе и с отдельной запятой, и с отличной идеей, но это не так. это по умолчанию представление для моей первой загрузки.
Попробуйте захватить оба селектора, разделенные запятой, а затем с помощью функции jQuery .attr()
чтобы заполнить правильную страницу администратора:
$('a[data-user="settings"],a[data-user="add"]').click(function(event) {
event.preventDefault();
$('.list-unstyled li').removeClass('active');
$('section.col-lg-8').replaceWith(formAdd);
$('.form-custom').load('includes/pages/admin/admin-user-'+$(this).attr('data-user')+'.php');
subHash = this.hash;
});