2015-12-16 28 views

回答

0

你需要看的第一空間的指數,然後添加特定類:

$('p').each(function() { 
    var word = $(this).html(); 
    var index = word.indexOf(' '); 
    if(index == -1) { 
     index = word.length; 
    } 
    $(this).html('<span class="first-word">' + word.substring(0, index) + '</span>' + word.substring(index, word.length)); 
}); 

然後風格的。 first-word

.first-word{ 
    font-family:'font1'; 
} 

欲瞭解更多信息,請參閱http://webdesignerhut.com/style-first-letter-word-line-and-paragraph-with-css-and-jquery/

+0

':第一letter'是第一個字母,而不是第一個字 –

相關問題