0

I am not familiar with jQuery so very much possible that I am overlooking something simple.

Is there a way to define these objects together, instead of 3 different instances?

      $( "#accordion") .accordion({
          active: false,
          collapsible: true,
          icons: icons,
          autoHeight: false,
          heightStyle: "content"
      });

      $( "#accordion_fulfillment") .accordion({
          active: false,
          collapsible: true,
          icons: icons,
          autoHeight: false,
          heightStyle: "content"
      });

      $( "#accordion_warehouse") .accordion({
          active: false,
          collapsible: true,
          icons: icons,
          autoHeight: false,
          heightStyle: "content"
      });

I have tried doing the obvious but it's not working $( "#accordion", "#accordion_fulfillment", "#accordion_warehouse") .accordion({....})

4

2 回答 2

4

您可以使用选择器尝试这种方式attribute

$( "[id^='accordion']") .accordion({ // <----this selects all ids which starts 
      active: false,                 //      with accordion
      collapsible: true,
      icons: icons,
      autoHeight: false,
      heightStyle: "content"
  });

在这里阅读更多jQuery("[attribute^='value']")

于 2013-03-05T07:29:35.647 回答
2

关!

$( "#accordion, #accordion_fulfillment, #accordion_warehouse") .accordion({....})
于 2013-03-05T07:25:46.187 回答