1

我们数据库中的所有数据均以全大写形式输入。当我提取该信息(即名字和姓氏)时,我希望它说“John Smith”与“JOHN SMITH”。我尝试使用text-transform:capitalize;,但只大写第一个字母。它不会使所有其他字母小写。我也试过这个(没有成功):

<div class="profile">
<h2 style="text-transform:lowercase;"><span style="text-transform: capitalize;">Welcome _MEM_FirstName_ _MEM_LastName_,</span></h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam neque lectus, molestie quis ullamcorper ac, vesti bu lum ut elit. Donec quis lacus sem, a pharetra neque. Cras ultricies purus ac ligula lacinia ullamcorper.</p>
<p>Your Walser Rewards card is also your My SA Rewards card. While at Super America locations you can get gas discounts and earn speedy rewards too.</p>
</div>

关于如何将文本从大写转换为大写的任何想法?

4

4 回答 4

2

不确定您是如何提取数据的,但您可以在提取单词后通过 Javascript 对其进行编辑。

var text = "JOHN SMITH"; //this would normally be the word you pulled
var textarray = text.toLowerCase().split(" "); // ["john", "smith"]
for (var i=0; i<textarray.length; i++) {
    textarray[i] = textarray[i].replace(textarray[i][0], textarray[i][0].toUpperCase());
}
//["John", "Smith"]

现在,textarray您可以在页面上随心所欲地将其打印出来。

于 2013-03-08T19:59:02.570 回答
1

这对 CSS 来说是不可能的,因为你的字母已经大写了,但是你可以用你的服务器端语言(例如 PHP)、JavaScript 甚至在数据库查询中做到这一点

于 2013-03-08T19:47:46.330 回答
1

这个问题没有 CSS 解决方案,afaik。

请参阅此处,以获取相关帖子。请先做好功课。

最好的方法是在数据库查询和应用程序将数据发送到模板之间格式化数据。

于 2013-03-08T19:46:38.360 回答
0

将字符串转换为小写, string modifiedString = myString.ToLower();在检索字符串后使用类似方法中的内容。然后text-transform: capitalize;在你的 CSS 中使用。

于 2013-03-08T19:50:46.903 回答