HTML 문서에서 <li>
클래스 이름을 확인한 다음이 확인란을 기반으로이 코드를 작성했습니다. 예 : <li class="books"></li>
- 확인란에는 'books'라는 라벨이 지정됩니다. 그러나 클래스에 공간이있는 경우 <li class="book case"></li
> 두 개의 태그, 즉 &이 생성됩니다. 나는 이것을하기를 원하지 않는다. 나는 두 단어로 구성된 체크 박스를 가질 수 있기를 원한다. 아래 코드에서 "이제는 모든 클래스 이름의 공백으로 구분 된 문자열이 저장되었습니다."라고 말합니다. 나는 어느 비트가 이것을하고 있는지 이해하지 못한다. 이 일이 일어나지 않도록 변경 될 수있는 명백한 것을 누군가는 볼 수 있습니까? 이 필요한 경우 더 많은 코드가jquery/javascript에서 공백으로 구분 된 함수 중지
var stringOfClassNames = '';
// grab the class name of each list item to build that string
$('.filterThis > li').each(function (i) {
var thisClassString = $(this).attr('class');
stringOfClassNames = stringOfClassNames +' '+ thisClassString
});
// now i have a space-delimited string of all class names stored
// in the stringOfClassNames variable.
// Trim spaces from the ends of that string:
stringOfClassNames = jQuery.trim(stringOfClassNames);
// i can't really do anything with it until it's an array, so
// convert that string to an array.
var arrayClasses = stringOfClassNames.split(' ');
// now for the isolating the filter that is common to all.
// must do before extracting only the unique classes
// one way to approach: count the number of times classes occur, and
// if any occur the same number of times as how many list items i have,
// assume that class is common to all list items, and remove it from
// the filter list. duplicate class on same item = problem, but
// i'm not thinking about that right now.
// i've also chosen sort the pre-unique'd array
// instead of sorting the unique'd array. i think i have to for the count.
var arrayClasses = arrayClasses;
totalNumberOfItemsToFilter = $('.filterThis > li').length;
...
자바 스크립트는 두 CSS 클래스book
및
case
는 하나의
book case
단어로 취급되어야한다는 것을 알고 가정되는 방법
'stringOfClassNames의 =의 stringOfClassNames + ''+ thisClassString'하면 문자열을하고있다. – Jack