嘿,我想知道如何使用jquery爲下面的腳本動態地獲取類名。如何使用jquery獲取類名?
的HTML輸出如下:
<div id="main-info-1" class="maini">
<p>this is a paragraph.</p>
</div>
所以,我試圖讓類名動態,而不是硬編碼像它上面。
有兩個部分,我需要得到的jQuery腳本類名稱:
1.) pc.children('div.maini').remove();
2.) maini_s = $('div.maini').remove();
正如你可以看到類的邁尼'是硬編碼和IM不確定如何動態獲取類名並把它正確地放在腳本中。
jQuery的文件:
<script type="text/javascript">
// make them global to access them from the console and use them
// in handlePaginationClick
var maini_s;
var num_of_arts;
var ipp;
function handlePaginationClick(new_page_index, pagination_container) {
var pc = $(pagination_container);
pc.children('div.maini').remove();
for(var i=new_page_index*ipp; i < (new_page_index+1)*ipp ;i++) {
if (i < num_of_arts) {
pc.append(maini_s[i]);
}
}
return false;
}
$(document).ready(function() {
maini_s = $('div.maini').remove();
num_of_arts = maini_s.length;
ipp = 3;
// First Parameter: number of items
// Second Parameter: options object
$("#News-Pagination").pagination(6, {
items_per_page:ipp,
callback:handlePaginationClick
});
});
</script>
任何幫助將是真棒,謝謝。
從哪裏動起來?你只需要它是一個全球js var? – Jage 2010-01-25 01:50:23
查看hasClass()的示例addClass()removeClass()和toggleClass() – 2010-01-25 07:42:19