2016-03-14 15 views
5
wordCount = {}; theWords = []; allWords = data.match(/\b\w+\b/g); //get all words in the document 

    for(var i = 0; i < allWords.length; i = i + 1){ 
     allWords[i] = allWords[i].toLowerCase(); 
     var word = allWords[i]; 
     if(word.length>5){ 
     if(wordCount[word]){ 
      wordCount[word] = wordCount[word]+1; 
     } 
     else{ 
      wordCount[word] = 1; 
     } 
     } 
    } 
var theWords = Object.keys(wordCount); // all words over 5 characters 
var result = ""; 
    for(var i = 0; i < theWords.length; i = i + 1){ 
     result = result + " " + theWords[i]; 
     $("theWords.eq[i]").css("fontSize" , (wordCount.length + 50) + 'px'); 

    } 
    return result; 
} 

Mam kłopoty ze składnią wiersza „$ (” thewords [i] .......”zmiany rozmiaru czcionki według liczyć słowa

Zdaję sobie sprawę, jak łatwo z pytanie to jest, a nie akademickich dla społeczności, ale jestem grzebanie z tej składni przez chwilę i nie można znaleźć żadnego konkretnego forum, aby poprawić mój błąd składniowy

Próbuję zmienić rozmiar czcionki zgodnie z do czasu pojawienia się tego słowa w dokumencie:
wordCount = liczba wyświetleń
theWo rds = wszystkie słowa Chciałbym, aby reguła miała zastosowanie do:

+0

to '$ ("thewords [I]")' elementy w dokumencie? Czy możesz dołączyć "html" do pytania? – guest271314

+0

poprawne, program od teraz poprawnie policzy każde słowo według inspektora sieci. –

+0

Czy '" theWords "' a 'className' of elements? Wypróbuj '$ (" .Words "). Eq (i)' – guest271314

Odpowiedz

0

Udało mi się coś zrobić z tym, co zrobiłeś, używając nieco więcej jQuery do zbudowania listy słów do pokazania. mam nadzieję, że to pomaga: D.

$(document).ready(function() { 
 
    
 
var data = $(".sometext").text(); 
 

 
wordCount = {}; theWords = []; allWords = data.match(/\b\w+\b/g); //get all words in the document 
 

 
for (var i = 0; i < allWords.length; i++){ 
 
    allWords[i] = allWords[i].toLowerCase(); 
 
    var word = allWords[i]; 
 
    if (word.length > 5) { 
 
    if (wordCount[word]) { 
 
     wordCount[word] = wordCount[word] + 1; 
 
    } else { 
 
     wordCount[word] = 1; 
 
    } 
 
    } 
 
} 
 

 
var theWords = Object.keys(wordCount); // all words over 5 characters 
 
    
 
for(var i = 0; i < theWords.length; i = i + 1) { 
 
    $('<span/>', { 
 
    'text': theWords[i] + " ", 
 
    'class': theWords[i] 
 
    }).appendTo('.result'); 
 
} 
 
    
 
for(var i = 0; i < theWords.length; i++) { 
 
    $("." + theWords[i]).css("font-size", 15 + wordCount[theWords[i]]*5 + "px"); 
 
} 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<p class="sometext">javascript is a language that could be a language without such things as language but not without things as parenthesis. language is the bigest word here.</p> 
 

 
<hr> 
 

 
<div class="result"></div>

Powiązane problemy