너무 길면 포럼 색인에서 각 항목의 제목을 짧게 할 수있는 플러그인을 만들고 있습니다. 그러나, 그것은 내가 예상했던 것보다 훨씬 더 어렵다.Uncaught TypeError : undefined is not function
실제로 DOM에 항목을 인쇄해야하는 부분을 제외하고 모든 것이 잘됩니다.
는이 오류를 얻을 :
Uncaught TypeError: undefined is not a function
가 여기에 내가 어떻게 작동하는지 보여 왼쪽 노트의 무리와 함께 내 코드입니다.
var minimize = function() {
$('.segment').each(function(){
var title_box = $(this).children('.title');
// Selects the container of the title.
var title = $(this).children('.title').text().trim();
// Takes the child title of the each .segment class and selects its innards.
console.log(title);
var res = title.split("");
// Splits the text into an array.
console.log(res);
var fragment = [];
// initializing the empty array
for (x = 0; x < 4; x++) {
fragment.push(res[x]);
console.log(fragment);
// Loops through to make sure it's not more than 5 characters long
};
var final = fragment.join("");
// Joins the broken up string together.
title_box.empty();
final.appendTo(title_box);
});
};
내가 잘못했다고 생각합니까? 그리고이 코드를 더 효율적으로 만들 수있는 다른 방법이 있다면 저에게 말하기를 주저하지 마십시오.
경우 오류를받을 수 있나요? 어느 선 이요? –
"final"변수는 조각에서 ""합쳐진 문자열이지만 jQuery 개체는 포함하지 않습니다. 은 $ (최종)이어야합니다. appendTo (제목 _ 상자); – Derek