在ASP.NET中使用JavaScript時,我需要將小寫字母轉換爲大寫字母。第一個字母大寫
如何在JavaScript中使用正確答案解決此問題?
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script language="JAVASCRIPT">
function capitalizeMe(obj) {
val = obj.value;
newVal = '';
val = val.split(' ');
for (var c = 0; c < val.length; c++) {
newVal += val[c].substring(0, 1).toUpperCase() +
val[c].substring(1, val[c].length) + ' ';
}
}
</script>
</head>
<body>
<form id="Form2" runat="server">
<asp:TextBox ID="TextBox1" runat="server" onblur="capitalizeMe(this)">
</asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</form>
</body>
</html>
請之前發佈SO上的搜索:http://stackoverflow.com/questions/1026069/capitalize-the-first-letter的dupplicate -of-string-in-javascript –