»
Tiếng AnhTiếng PhápTiếng Việt

In - Đổi kí tự đầu dòng sang chữ hoa - JavaScriptBank.com

Phiên bản đầy đủ: jsB@nk » Biểu mẫu » Đổi kí tự đầu dòng sang chữ hoa
URL: https://www.javascriptbank.com/converting-a-string-to-title-sentence-case.html

Đổi kí tự đầu dòng sang chữ hoa © JavaScriptBank.comMột đoạn mã JavaScript khác để đổi kí tự đầu tiên của chuỗi do người dùng nhập vào sang chự hoa.

Phiên bản đầy đủ: jsB@nk » Biểu mẫu » Đổi kí tự đầu dòng sang chữ hoa
URL: https://www.javascriptbank.com/converting-a-string-to-title-sentence-case.html



JavaScript
<SCRIPT language=javascript>function rtrim(strInput) {  while (1) {    if (strInput.substring(strInput.length - 1, strInput.length) != " ")      break;    strInput = strInput.substring(0, strInput.length - 1);  }  return strInput;}function ltrim(strInput) {  while (1) {    if (strInput.substring(0, 1) != " ")      break;    strInput = strInput.substring(1, strInput.length);  }  return strInput;}function trim(strInput) {  var tmpstr = ltrim(strInput);  return rtrim(tmpstr);}function sentencecase(strInput){strInput = trim(strInput);strInput = ' ' + strInput;strInput=strInput.toLowerCase();var firstcharlc=strInput.charAt(1);var firstcharuc=firstcharlc.toUpperCase();firstcharuc = " " + firstcharuc;firstcharlc = " " + firstcharlc;strInput=strInput.replace(firstcharlc, firstcharuc);strInput=trim(strInput);var len = strInput.length;var spacePos = strInput.indexOf(' ');while (spacePos != -1) {var firstcharlc = strInput.charAt(spacePos+1);var firstcharuc=firstcharlc.toUpperCase();firstcharuc = " " + firstcharuc;firstcharlc = " " + firstcharlc;strInput=strInput.replace(firstcharlc, firstcharuc);strInput=trim(strInput);spacePos = strInput.indexOf(' ',spacePos+1);}return strInput;}</SCRIPT><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<FORM name=MYFORM><INPUT name=mySentence> <INPUT onclick="document.MYFORM.mySentence.value = sentencecase(document.MYFORM.mySentence.value);" type=button value="Click Here"> </FORM><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->