How to display random quotes with author name in bold?
I got a piece of code that display a random quote from a text file. It´s working fine. However I would like to style the authors name in bold. The text file "quotes.txt" looks like this:
Because we're friends, I'm gonna tell you something nobody else knows. I'm homophobic. Author@ Cookies, everyone! Nourishment is most important in the morn开发者_如何学Pythoning. Author@ Objection, your Honor. You can't preface your second point with "first of all." Author@ Denny Crane. Author@ You know what I'm going to do, Brian, just to show you there are no hard feelings? I'm going to sleep with your wife. Author@ Did something happen? Was I in the room when it happened? Author@
jQuery:
<script type="text/javascript">
$(document).ready(function() {
$.get('path/to/RandomQuote.txt', function (data) {
var quotes = data.split("\@");
var idx = Math.floor(quotes.length * Math.random());
$('.quotes').html(quotes[idx]);
});
});
</script>
replace
$('.quotes').html(quotes[idx]);
using this,
$('.quotes').html(quotes[idx].substring(0,quotes[idx].lastIndexOf('.')) +"<b>"+quotes[idx].substring(quotes[idx].lastIndexOf('.') + 1)+"</b>");
LTTP but you can just put raw HTML in the text file. This will give you greater flexibility with styling.
精彩评论