2012-07-20 35 views
0

假設我有很多DIV s,其中有不同的ID s,我想插入一小段html到所有這些DIV s中,使用不同的ID s。我試過jquery給多個DIV分配相同的文本

$("#lblTopPager", "#lblBottomPager").html('hello my data'); 

但它不起作用。任何人都可以告訴我做正確的方法嗎?

+0

http://api.jquery.com/multiple-selector/ – 2012-07-20 14:23:58

回答

1

元素需要一個逗號分隔的清單,現在你給上下文,基本上找一個元素與ID lblTopPager裏面的元素與ID lblBottomPager,其中使用$('#lblBottomPager').find('#lblTopPager')就好像你。

要定位在同一時間兩個或多個元素,你可以這樣做:

$("#lblTopPager, #lblBottomPager").html('hello my data'); 
+0

我在這裏可以使用通配符,因爲很少一部分是固定的。可以寫這條線,如$(「input [id * ='lblTopPager'],input [id * ='lblBottomPager']),這是lblTopPager跨度基本上 – Thomas 2012-07-20 14:35:40

+0

'$(」input [id * ='lblTopPager'],input [id * ='lblBottomPager']「)'應該可以工作! – adeneo 2012-07-20 14:52:50

相關問題