这个JQUERY脚本中plus运算符的含义是什么

时间:2010-12-13 07:57:22

标签: javascript jquery

我想在这个脚本中询问plus运算符的意思+ + i +:

i=0;
// next line in scripts write this code :
$('.container[data-id='+i+']').hide(); // +i+ what the meaning of it

需要帮助感谢TON

4 个答案:

答案 0 :(得分:4)

+用于连接字符串

在这种情况下,它用于在{strong> .container [data-id = 和]

之间连接i的值

假设我正在存储一些值,例如0,那么这将被评估为

$('.container[data-id=0]').hide();

答案 1 :(得分:3)

这会将变量i中的值与剩余的字符串连接起来。

请参阅Concatenating strings

答案 2 :(得分:2)

+ is used for string concantination 

var test= "hello" + "world";// gives helloworld

它也用于添加值

var c= a+ b// if a=10 and b=20 it gives 30

答案 3 :(得分:2)

JavaScript中的+运算符用于算术运算和字符串运算。 如果两个操作数均为Number类型,则结果为总和。如果其中一个操作数不是数字,则两者都将转换为String并连接。应谨慎使用。