For the function of the eval () in JS and write a function trim () Remove the left and right spaces of the string.
Trim () is referred to the jquery source code, you can be assured to use.
For JS in the eval () function of understanding is my experience is not necessarily correct.
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<title> New Document </title>
<body>
JS in the processing of string filter before and after the space of the trim function is not,<br>
And jquery added this very common function, its source code is as follows <br>
function Trim (t) {<br>
Return (t| | ""). Replace (/^\s+|\s+$/g, "");<br>
}<br>
Sometimes we don't need jquery to join the entire jquery library for a function,<br>
Then we can put the source code to write a trim function on the line. <br>
</body>
<script>
var f= ' Hello ';
alert (f);
/*
Here, by the way, the eval () function, which computes the contents of the parentheses as a JS script,
You can also compute a mathematical operation, or you can compute a string.
In short, it is not a simple string concatenation function.
You can take it as the JS script in JS.
This is similar to JSP, JSP is embedded in the HTML Java code,
The content in the eval () bracket is the JS code embedded in JS.
*/
Eval ("Alert (' +f+ ')");//Compute JS script, same as alert (f) effect.
Eval ("var gg= ' haha '");
Alert ("GG");//eval is embedded in the JS code, equivalent to the Var gg= ' haha ', alert (GG);
Alert (eval (' 3+4 '));//computational mathematical operation, result 7
Alert (eval (' 3 ' + ' 4 '));//compute string, result 34
Alert ("Start" +trim (' abc def ') + "End");
The Trim function in jquery filters out the first space.
function Trim (t) {
Return (t| | ""). Replace (/^\s+|\s+$/g, "");
}
</script>