About case conversion is very simple is two methods, check the tutorial can be very clear, here is simple to write:
var str0= "Baidu"; Str0.touppercase (); // Convert to uppercase Str0.tolowercase (); // Convert to lowercase
Then let's take a look at the split () method: There are several common return results:
varStr= "Baidu.com"; Alert (Str.split (".") );//the return is [' Baidu ', ' com '] varStr1= "Baidu"; Alert (Str1.split ("") );//the return is [' B ', ' A ', ' I ', ' d ', ' U '] varStr2= "McDull"; Alert (Str2.split ("") );//the return is [' wheat ', ' pocket '] varStr3= "McDull is a cute pig."; Alert (Str3.split ("cute"));//the return is [' McDull is head ', ' pig '] varSTR4 = ' 2018-01-09-18-00 '; Alert (Str4.split ("-", 3));//return is [' 2018 ', ' the '
Then you know these words, take a look at the simple small example: enter the content in the following input click Send, and then push the content into the box above, and push the text to add the background color
Write the layout first:
css:div {width:300px; height:200px; border:1px solid #333; background: #fff; padding : 20px; line-height:40px; } span {padding:5px 15px; font-family: Microsoft Jacob Black;} HTML: < div id = "box" ></ div > < input type = "text" /> < input type = "button" value = "Send" />
Focus on JS, here to use the split () method:
<script>window.onload=function(){ varInp=document.getelementsbytagname ("Input"); varObox=document.getelementbyid ("box"); vararrcolor=["#ff0", "#00f", "#f00", "#ff6100"] inp[1].onclick=function(){ varStr=inp[0].value; varArr =str.split (""); for(vari=0;i<arr.length;i++) {Arr[i]= ' <span style= ' background: ' + arrcolor[i%arrcolor.length] + '; ' > ' +arr[i]+ ' </span> '} obox.innerhtml+ = Arr.join (");//Join (') is the conversion of an array to a string } };</script>
Run as follows:
Of course, this example project should not use a lot of, but a lot of similar principles of the use of the split method, most of them are original aim, are like this! So, hope to be useful to everyone!
All right, that's it for today!
Native JS case conversion and Split split string method