<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
<script type="text/javascript">
var str = " hyu kop jkl ";
String.prototype.trim=function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.ltrim=function(){
return this.replace(/(^\s*)/g,"");
}
String.prototype.rtrim=function(){
return this.replace(/(\s*$)/g,"");
}
alert('['+str.trim()+']')
function trim(str){
return str.replace(/(^\s*)|(\s*$)/g, "");
}
function ltrim(str){
return str.replace(/(^\s*)/g,"");
}
function rtrim(str){
return str.replace(/(\s*$)/g,"");
}
alert(trim(str))
</script>
</html>