当前位置:编程学习 > JS >>

英文网站首个字母大写的js代码以及css代码

实现英文网站首个字母大写的js代码,比较方便,有需要的试试吧

<script language=javascript>
String.prototype.toTitleCase = function() {
return this.replace(/([\w&`'‘’"“.@:\/\{\(\[<>_]+-? *)/g, function(match, p1, index, title) {
if (index > 0 && title.charAt(index - 2) !== ":" &&
match.search(/^(a(nd?|s|t)?|b(ut|y)|en|for|i[fn]|o[fnr]|t(he|o)|vs?\.?|via)[ \-]/i) > -1)
return match.toLowerCase();
if (title.substring(index - 1, index + 1).search(/['"_{(\[]/) > -1)
return match.charAt(0) + match.charAt(1).toUpperCase() + match.substr(2);
if (match.substr(1).search(/[A-Z]+|&|[\w]+[._][\w]+/) > -1 ||
title.substring(index - 1, index + 1).search(/[\])}]/) > -1)
return match;
return match.charAt(0).toUpperCase() + match.substr(1);
});
};
var s = " zhaoxi banner logo design online ";
s = s.toTitleCase();
window.alert(s);
</script>

同时分享CSS代码实现网站内容首个字母大写的代码,DIV CSS text-transform英文字母全大写小写_CSS首字母大写

Capitalize 英文拼音的首字母大写
Uppercase 英文拼音字母全大写
Lowercase 英文拼音字母全小写
例如代码如下:
div{text-transform:capitalize}

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,