That is the topic from Baidu IFE:
A single line becomes a multi-line input box, a button, the input box is used to enter the user's interests, allowing users to use line wrapping, space (full-width/half-width), comma (full-width/half-width), comma, semicolon as a separate hobby.
And then there's my solution:
or to use regular expression, the result is correct, if there is a better way to remember to tell me AH ~ ~ ~
var str=$ ("#text"). Val (); var strs = Str.split (/[,,; \s+]/); alert (strs.length);
The whole problem is to divide the input information, go empty, go heavy, My code is Jiangzi, learn from each other ~ ~ ~
<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "Utf-8" /> <Scripttype= "Text/javascript"src= "Js/jquery.js"></Script> <Scripttype= "Text/javascript">$ (document). Ready (function(){ $("#submit"). Click (function(){ varStr=$("#text"). Val (); varSTRs=Str.split (/[,,,; \s+]/); alert (strs.length); Console.log (STRs); varNewstrs= []; varJSON={}; for(i=0; I<Strs.length;i++){ if(Strs[i]) {if(!Json[strs[i]]) {Newstrs.push (strs[i]); Json[strs[i]]=1; } } } }) }) </Script></Head><Body> <Div>Stage 2</Div> <textareatype= "text"style= "width:400px;"ID= "text"></textarea> <inputtype= "button"value= "Submit"ID= "Submit" /> <Divstyle= "border:1px"></Div> </Body></HTML>
Split multiple separators for splitting