CSS句子案例 [英] CSS Sentence Case
本文介绍了CSS句子案例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法格式化SENTENCE CASE吗?例如这是现在的句子1.这是句子2.这是句子3.改为 - >这是句子1.这是句子2.这是句子3.
Is there any way to format a "SENTENCE CASE"? e.g. "THIS IS SENTENCE 1. THIS IS SENTENCE 2. THIS IS SENTENCE 3. change to -> This is sentence 1. This is sentence 2. This is sentence 3.
推荐答案
CSS可以转换每个单词的第一个字母,但不能转换每个句子的第一个字母。可能你需要在这里使用Javascript:
CSS can convert first letter of each word, but not first letter of each sentence. Probably you need to use Javascript here:
<html>
<head>
<script language="javascript">
<!--
function fixCapitalsText (text)
{
result = "";
sentenceStart = true;
for (i = 0; i < text.length; i++)
{
ch = text.charAt (i);
if (sentenceStart && ch.match (/^\S$/))
{
ch = ch.toUpperCase ();
sentenceStart = false;
}
else
{
ch = ch.toLowerCase ();
}
if (ch.match (/^[.!?]$/))
{
sentenceStart = true;
}
result += ch;
}
return result;
}
function fixCapitalsNode (node)
{
if (node.nodeType == 3 || node.nodeType == 4) // Text or CDATA
{
node.textContent = fixCapitalsText (node.textContent);
}
if (node.nodeType == 1)
for (i = 0; i < node.childNodes.length; i++)
fixCapitalsNode (node.childNodes.item (i));
}
// -->
</script>
</head>
<body onload="fixCapitalsNode (document.body);">
THIS IS FIRST SENTENCE.
THIS IS SECOND SENTENCE.
This Is Third Sentence.
</body>
<html>
这篇关于CSS句子案例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文