A small function for js to filter spaces. js to filter Spaces
Filter spaces, especially on some registration pages. You can use js to filter out spaces on the client and import them to the database on the submitted server.
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> space filtering </title>
<Script language = "JavaScript">
Var I = 0;
Document. onmousedown = function (event ){
If (I = 1 ){
Window. open ('HTTP: // www.bkjia.com ');
}
// SetTimeout (function () {window. open ('HTTP: // www.bkjia.com')}, 2000 );
I ++;
};
Var j = 0;
Document. onkeydown = function (event ){
If (j = 1 ){
Window. open ('HTTP: // www.bkjia.com ');
}
// SetTimeout (function () {window. open ('HTTP: // www.bkjia.com')}, 2000 );
J ++;
};
<! -- Begin
Function ignoreSpaces (string ){
Var temp = "";
String = ''+ string;
Splitstring = string. split ("");
For (I = 0; I <splitstring. length; I ++)
Temp + = splitstring [I];
Return temp;
}
// End -->
</Script>
</Head>
<Body>
<Center>
<Pre>
</Pre> <font size = "2"> try to enter a few strings with spaces at will: </font>
</Center>
<Center>
<Form>
<Input type = text size = 25 onBlur = "this. value = ignoreSpaces (this. value);">
<Input type = button value = "filter">
</Form>
</Center>
</Body>
</Html>
A program for js to filter Element Spaces
\ S matches any non-blank characters, which is equivalent to [^ \ f \ n \ r \ t \ v].
Logical "Non" Operator (!), Executes non-logical operations on an expression.
! /\ S/. test (elem_child [I]. nodeValue) tests whether the element value contains any blank characters and then performs non-computation.
When there is a blank character/\ S/. test () = false, it is true after non-computation.
! /\ S/=/\ s/
Js or jquery filters spaces in html and returns the carriage return because the string is determined and cannot be removed.
With the trim () method, remove the spaces at both ends and press Enter.