0

コードを 1 つのステップ関数全体に単純化したいと考えています。同じ属性と機能を持っているため、1 つのアクションですべてをマージする呼び出し関数が正確にはわかりません。

$('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;
});

別々のコンマで両方を含めることは素晴らしいアイデアになると思いましたが、そうではありません。ビューをデフォルトで最初の読み込みにします。

4

1 に答える 1

1

コンマで区切られた両方のセレクターを取得してから、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;
});
于 2013-11-04T05:21:50.553 に答える