更改每个单词的第一个字母的值 [英] Changing the value of the first letter of each word

查看:137
本文介绍了更改每个单词的第一个字母的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用jQuery,CSS或PHP来增加字符串中每个单词的第一个字母的字体大小。例如,我要在h1标签中有一个标题,例如:

I'm attempting to either use jQuery, CSS or PHP to increase the font size of the first letter of each word in a string. For example, I'm going to have a title in h1 tags like so:

<h1>The title of this page goes here</h1>

我想要将所有文本转换为大写(CSS没有问题)增加字符串中出现的第一个字母的字体大小。使用CSS或jQuery,有没有办法选择每个单词的第一个字母并修改它?

I'm wanting to text transform all the text to uppercase (no problem with CSS), but then increase the font size of the first letter that appears in the string. With CSS or jQuery, is there a way to select the first letter of each word and modify it?

推荐答案

$(document).ready(function() {
    var words = $('h1').text().split(' ');
    var html = '';
    $.each(words, function() {
        html += '<span style="font-size:200%">'+this.substring(0,1)+'</span>'+this.substring(1) + ' ';
    });
    $('h1').html(html);
});

下面是一个操作示例: http://jsfiddle.net/hCvsu/1/

Here's an example of it in action: http://jsfiddle.net/hCvsu/1/

这篇关于更改每个单词的第一个字母的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆