2013-03-05 35 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