Sunday, 15 July 2012

jquery - FOR IF Loop in javascript -


I have a simple question I want to make a statement in this code ( if (i = 2) { Str + = 'test';} ):

  var data = feedback information; Var str = '& lt; Ul & gt; '; (Var I = 0; I & lt; data. Lamps; I ++) {str + = '& lt; Li & gt; & Lt; A href = "# blog? Blog_id = '+ data [i] [0] +'" data-transition = "slide" & gt; '+ Data [i] [1] +' & lt; / A & gt; & Lt; / Li & gt; '; If (I = 2) {str + = 'test';}} str + = '& lt; / Ul & gt; '; $ ('#product') HTML (STR) }   

When I do this, it places the word 'test' on line, not just line 2.

To compare two values, == or = == Use:

  if (I === 2) {str + = 'test';}   

The result of> I = 2 , which changes the value of i , is 2 , which is correct as if Evaluates.

No comments:

Post a Comment