2013-03-05 40 views
0

我对jQuery并不熟悉,所以非常可能我忽略了一些简单的东西。Jquery中的多个声明

有没有办法一起定义这些对象,而不是3个不同的实例?

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

我试图做的很明显,但它的工作不是$( “#accordion”, “#accordion_fulfillment”, “#accordion_warehouse”).accordion({....})

回答

2

关闭!

$("#accordion, #accordion_fulfillment, #accordion_warehouse") .accordion({....}) 
+0

如此接近......可恶 – 2013-03-05 07:27:33

+0

关心帮助 - http://stackoverflow.com/questions/15218364/identify-the-dom-element-selector-and-tab-automatically – 2013-03-05 07:49:12

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']")

+0

如果感兴趣的东西要难得多 - http://stackoverflow.com/questions/15218364/identify-the-dom-element-selector-and-制表自动 – 2013-03-05 07:49:36