JS 操作符整理[推荐收藏]

所属分类: 网络编程 / JavaScript 阅读数: 1293
收藏 0 赞 0 分享

Arithmetic Operators
算术运算符

Operator Description Example Result
+ Addition
x=2
y=2
x+y
4
- Subtraction
x=5
y=2
x-y
3
* Multiplication
x=5
y=4
x*y
20
/ Division
15/5
5/2
3
2.5
% Modulus (division remainder)
余数
5%2
10%8
10%2
1
2
0
++ Increment
递增
x=5
x++
x=6
-- Decrement
递减
x=5
x--
x=4

Assignment Operators
赋值运算符

Operator Example Is The Same As
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
%= x%=y x=x%y

Comparison Operators
比较(关系)运算符

Operator Description Example
== is equal to
等于
5==8 returns false
=== is equal to (checks for both value and type)
等于(检查值和类型)*全吻合才算相等
x=5
y="5"

x==y returns true
x===y returns false

!= is not equal
不等于
5!=8 returns true
> is greater than
大于
5>8 returns false
< is less than
小于
5<8 returns true
>= is greater than or equal to
大于等于
5>=8 returns false
<= is less than or equal to
小于等于
5<=8 returns true

Logical Operators
逻辑运算符

Operator Description Example
&& and
x=6
y=3

(x < 10 && y > 1) returns true

|| or
x=6
y=3

(x==5 || y==5) returns false

! not
x=6
y=3

!(x==y) returns true

String Operator
串符(连接作用)

A string is most often text, for example "Hello World!". To stick two or more string variables together, use the + operator.
在文字当中使用的比较多,举例来说“Hello World!”要将两个或多个字符串变量衔接在一起的话就得使用 + 符号

txt1="What a very"
txt2="nice day!"

txt3=txt1+txt2 

The variable txt3 now contains "What a verynice day!".
txt3变量现在包含“What a verynice day!”(把1和2衔接起来了)

To add a space between two string variables, insert a space into the expression, OR in one of the strings.
要给两个字符串变量中间添加空格就得在表达式里插入空格,或在其中的一个加上(空格)

txt1="What a very"
txt2="nice day!"
txt3=txt1+" "+txt2
or
txt1="What a very "
txt2="nice day!"
txt3=txt1+txt2

The variable txt3 now contains "What a very nice day!".
现在变量txt3为“What a very nice day!”

Conditional Operator
条件运算符

JavaScript also contains a conditional operator that assigns a value to a variable based on some condition.
JS有根据条件不同给变量不同值的条件运算符

Syntax
语法

variablename=(condition)?value1:value2 

Example
例子

greeting=(visitor=="PRES")?"Dear President ":"Dear "

If the variable visitor is equal to PRES, then put the string "Dear President " in the variable named greeting. If the variable visitor is not equal to PRES, then put the string "Dear " into the variable named greeting.
如果变量visitor的值等于PRES那么greeting的值就为"Dear President "。如果不为PRES那么greeting的值就为"Dear"

更多精彩内容其他人还在看

基于jquery封装的一个js分页

基于jquery封装的一个js分页代码,需要的朋友可以参考下。
收藏 0 赞 0 分享

关于js datetime的那点事

关于js datetime的一些使用经验分享,想要了解datetime日期操作的朋友可以参考下。
收藏 0 赞 0 分享

js 关于=+与+=日期函数使用说明(赋值运算符)

js 关于=+与+=日期函数使用说明(赋值运算符),可以看下,就是一些运算符的使用,看哪个更适合你。
收藏 0 赞 0 分享

JS 操作符整理[推荐收藏]

JS 操作符主要包括算术运算符,赋值运算符,比较(关系)运算符,逻辑运算符,串符(连接作用),条件运算符等
收藏 0 赞 0 分享

让html的text输入框只能输入数字和1个小数点(0-59之间可改)

今天有同事需要这个功能,主要是限制用户输入不符合规范的数字与小数点导致不好计算价格问题,特整理了下面的代码,需要的朋友可以参考下。
收藏 0 赞 0 分享

Jquery 获取checkbox的checked问题

这个郁闷了,今天写这个功能的时候发现了问题,上网找了好多资料对照,更加纠结
收藏 0 赞 0 分享

jQuery EasyUI API 中文文档 - DataGrid数据表格

jQuery EasyUI API 中文文档 - DataGrid数据表格使用说明,需要的朋友可以参考下。
收藏 0 赞 0 分享

jQuery EasyUI API 中文文档 - PropertyGrid属性表格

jQuery EasyUI API 中文文档 - PropertyGrid属性表格使用介绍,需要的朋友可以参考下。
收藏 0 赞 0 分享

20款效果非常棒的 jQuery 插件小结分享

这篇文章向大家推荐20款效果非常棒的 jQuery 插件。jQuery 是一个非常优秀的JavaScript库,它简化了 HTML 文档遍历,事件处理,动画以及 Ajax 交互,同时也改变了很多人编写 JavaScript 代码的方式
收藏 0 赞 0 分享

基于Jquery插件开发之图片放大镜效果(仿淘宝)

公司某个网站,需要实现图片预览效果,并能像淘宝一样实现局部分大,使用jquery的朋友可以参考下。
收藏 0 赞 0 分享
查看更多