The solution that javascript trim functions cannot be used in IE is javascripttrim.
Javascript trim functions are available in firefox.
<script language="javascript"> var test1 = " aa "; test1 = test1.toString(); test1 = test1.trim(); </script>
There is no problem in using Firefox, but an error is reported in IE.
So we can modify it.
String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"");}
Add this sentence in the header, and the above statement can be run in both IE and FF.
<script language="javascript"> String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"");} var test1 = " aa "; test1 = test1.toString(); test1 = test1.trim(); </script>
JQuery provides the following methods:
<!DOCTYPE html>
The trim () function in JQuery is supported in firefox, but not in IE. How can I make IE9 compatible?
$. Each (ob, function (k, val ){
If (k = 'cname '){
Var s = $. trim (ob. cname );
$ ("# Nianji "). append ("<option value = '" + s + "'>" + ob. cname. trim () + "</option> ");
}
});
This is all supported. $. trim ()
Which of the following experts added the trim () function to javascript gave me some advice: Why can't I verify the Code as follows?
<Form id = "form1" name = "form1" method = "post" action = "" onsubmit = "return yz ()">
<Input type = "text" name = "text1"/>
<Input type = "submit" name = "Submit" value = "submit"/>
</Form>
<Script language = javascript>
String. prototype. Trim = function ()
{
Return this. replace (/(^ \ s *) | (\ s * $)/g ,"");
}
Function yz ()
{
If (document. form1.text1. value. Trim () = "")
{
Alert ("null ");
Return false;
}
}
</Script>