js 取掉空格自定义函数

js  取掉空格自定义函数

 1 //取掉左右空格:
 2
 3 function trim(str){
 4
 5    return str.replace(/(^\s*)|(\s*$)/g, "");
 6
 7 }
 8
 9 //取掉左边空格:
10
11 function ltrim(str){
12
13  return str.replace(/(^\s*)/g,"");
14
15 }
16
17 //取掉右边空格:
18
19 function rtrim(str){
20
21    return str.replace(/(\s*$)/g,"");
22
23 }
24
25 //取掉所有空格:
26
27 function trimAll(str){
28
29 return str.replace(/\s/g, "");
30
31 //return str.replace(/\s+/g, "");//两个都可以,如何第一个不可用,可使用第二个
32
33 }
34
35 //替换所有空格:
36
37 function replaceAll(str){
38
39   return str.replace(/[ ]/g, "-");//-:是指要把空格替换的字符
40
41 }
时间: 2024-08-03 21:37:48

js 取掉空格自定义函数的相关文章

在JS中,一个自定义函数如何调用另一个自定义函数中的变量

function aa1511() { var chengshi="马鞍山"; var shengfen="安徽省"; return shengfen+"@"+chengshi; } function xialachaxun() { var hanshu=aa1511().split("@"); alert(hanshu[0]+','+hanshu[1]); }

for循环+简单函数和自定义函数

for循环:结构更加紧凑    例:for(var a = 1: a <= 10;a++){console.log(a)} for循环1,2,4步是可选的     下面的情况也是可以的.但是一般不这么写,不规范 // for (var n = 0; ; n++) { // } // var n = 0 // for (; n < 10; n++) { // } 三种循环的联系和区别   1.都是会反复执行的代码块 2.大部分情况下可以互相替换 3.do...while至少执行一次,while和

在js自定义函数中使用$(event.target)代替$(this)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <ti

07 js自定义函数

学习目标: 1.充分理解函数的概念 2.能熟练的自定义函数 3.掌握js中常用的系统函数 一个简单的加减乘除案例(说明函数的必要性): <html> <head> <script language="javascript"> <!-- //输入两个数,再输入一个运算符(+-*/),得到结果 var num1 = window.prompt("请输入第1个num"); var num2 = window.prompt(&quo

JS基础(五)自定义函数

作用:是为了让重复使用的语句,方便进行调用. 定义格式: function 自定义函数名 (参数1, 参数2,...) { 执行的语句 } 函数的封装:把语句放到函数中去的过程. 参数:通过参数的改变,改变函数的结果. 传参:使用参数调用函数. 在传参的过程中,是有顺序要求的,注意不能把顺序搞乱. 变量的作用域:1.全局变量:在程序中各函数都能够调用. 2.局部变量:只在定义的函数中能够调用.

Microsoft SQL Server 自定义函数整理大全

01.去除字符串中的html标记及标记中的内容 [叶子函数分享一]去除字符串中的html标记及标记中的内容 --1.创建函数 create function [dbo].[clearhtml] (@maco varchar(8000)) returns varchar(8000) as begin     declare @i int     while 1 = 1     begin        set @i=len(@maco)        set @maco=replace(@maco

SQL常用自定义函数

去除字符串中连续的分割符 --创建函数 create function [dbo].[m_delrepeatsplit] ( @str varchar(2000), @split nvarchar(200) ) returns nvarchar(2000) as begin --begin declare declare @count int,@i int,@isnull int declare @newchar nvarchar(200),@nn nvarchar(300) set @coun

Mysql函数(内置函数,自定义函数)

简述 SQL:结构化查询语言,是一门编程语言,是用于管理数据库的编程语言. 元素:数据,数据类型,变量,函数,流程控制,运算符,注释. 注释: 行: # –[空格] 块: /* */ select * from swpu_stu #where id=2; ; select * from swpu_stu -- where id=2; ; 结束符: select * from swpu_stu where id=2\g select * from swpu_stu where id=2\G 可以使

shell学习总结之自定义函数

shell学习总结之自定义函数 Myfun (){ echo patams1 is $1 echo -n "now i is $i " ! [ "$i" ] && exit ; echo jj return '1' } myf=$(Myfun); echo myf Myfun 12 unset Myfun Myfun echo 'the end !'$myf 别人的 #! bin/bash # ----------------------------