안녕하세요, 아래 스크립트의 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();
당신이 하드 코딩 클래스 'maini'을 볼 수 있고 클래스 이름을 동적으로 가져 오는 방법을 확실 메신저 수 있듯이이 그것을 스크립트에 올바로 넣으십시오.
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>
이에 어떤 도움이 좋지 않을까, 감사합니다. 클래스 이름을 얻기 위해 jQuery를 사용
는
어디에서 동적으로 고정합니까? 방금 글로벌 js var해야합니까? – Jage
hasClass() addClass() removeClass() 및 toggleClass()에 대한 예제를 살펴보십시오. –