作家
登录

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

作者: 来源:www.28hudong.com 2013-03-30 00:38:59 阅读 我要评论

Arithmetic Operators算术运算符 Operator Description Example Result + Addition 加 x=2y=2x+y 4 - Subtraction 减 x=5y=2x-y 3 * Multiplication 乘 x=5y=4x*y 20 / Division 除 15/55/2 32.5 % Modulus (division remainder) 余数 5%210%810%2 120 ++ Increment递增 x=5x++ x=6 -- Decrement递减 x=5x-- 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=5y="5" x==y returns truex===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=6y=3 (x < 10 && y > 1) returns true || or 或 x=6y=3 (x==5 || y==5) returns false ! not 非 x=6y=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+" "+txt2ortxt1="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"

  推荐阅读

  读JavaScript DOM编程艺术笔记

1.获得当前元素的下一个元素 复制代码 代码如下: function getNextElement(node){ if(node.nodeType==1){ return node; } if(node.nextSibling){ return getNextElement(node.nextSibling); } return null; }; 2.>>>详细阅读


本文标题:JS 操作符整理[推荐收藏]

地址:http://www.17bianji.com/kaifa2/JS/23910.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)