Javascript foreach array key values, output to html -


How do I loop through an array key to output my values ​​to HRM?

Working with Layouts I thumbnail grid, 3 columns by 2 columns is a caption below each thumbnail. The selection of any thumbnail opens the hidden container, which also has 3 columns and 2 rows of a grid is. Many images and captions within that hidden container are going to be identical to the same duplicate HTML rather than being identical. I thought that I can put each one in an array and refer to those values ​​which Is connected with. I will make a loop at the moment but decide.

  var img = ['image01.jpg', 'image02.jpg', 'image03.jpg', 'image04. Jpg '] var Description = [' Aaaa ',' BBBBBB ',' CCCCC ',' DDDDD ']; $ ("#yin"). Click (function () {var img = [0,2]; var description = [0,1]; $ (step) .each (function () {document.getElementById ("img"). WinnerHTML ();} ); $ (Imgs) .each (function () {document.getElementById ("img"). InnerHTML ();});}); & Lt; Div class = "container" & gt; & Lt; Ul class = "row-fluid" & gt; & Lt; Li class = "span4" id = "yin" & gt; & Lt; Div class = "line-fluid" & gt; & Lt; Img src = "yin.jpg" /> & Lt; H3 & gt; Yin & lt; / H3 & gt; & Lt; / Div & gt; & Lt; / Li & gt; & Lt; Li class = "span4" id = "yang" & gt; & Lt; Div class = "line-fluid" & gt; & Lt; Img src = "yang.jpg" /> & Lt; H3 & gt; Yang & lt; / H3 & gt; & Lt; / Div & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; Div class = "line-fluid" & gt; & Lt; Div class = "span12" & gt; & Lt; Div class = "show details description" & gt; & Lt; Div class = "detail-content" & gt; & Lt; Div id = "img" & gt; & Lt ;! - Loop (image01 and image03 for yin) - & gt; & Lt; / Div & gt; & Lt; Div id = "description" & gt; & Lt ;! - Loop ('yaaaa', 'bbbbbb' for yin) - & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;    

There is a problem with that code before coming into looping, img < / Code> and details variables are being repatriated within your click function. What do they intend to do? By the comments given in your code, they indicate which index of the array to use.

  var images = ['image01.jpg', 'image02.jpg', 'image03.jpg' 'image04.jpg']; Var Description = ['Aaaa', 'BBBBBB', 'CCCCC', 'DDDDD']; $ ("#yin"). Click (function () {var imgIndices = [0,2]; var details index = [0,1]; $ ("# img") .html (""); $ ("#" ("#"); $ (Imgindss) .ech (function (i, o) {$ ("#img"). Append ("& lt; img src = \" + + image [o] + "(" & Details "); & lt ; & Lt; p & gt; & quot ;;);}); $ (wide indices) .each (function (i, o) {$ ("# description"). / P & gt; ");}) ;}); & Lt; Div class = "container" & gt; & Lt; Ul class = "row-fluid" & gt; & Lt; Li class = "span4" id = "yin" & gt; & Lt; Div class = "line-fluid" & gt; & Lt; Img src = "yin.jpg" /> & Lt; H3 & gt; Yin & lt; / H3 & gt; & Lt; / Div & gt; & Lt; / Li & gt; & Lt; Li class = "span4" id = "yang" & gt; & Lt; Div class = "line-fluid" & gt; & Lt; Img src = "yang.jpg" /> & Lt; H3 & gt; Yang & lt; / H3 & gt; & Lt; / Div & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; Div class = "line-fluid" & gt; & Lt; Div class = "span12" & gt; & Lt; Div class = "show details description" & gt; & Lt; Div class = "detail-content" & gt; & Lt; Div id = "img" & gt; & Lt ;! - Loop (image01 and image03 for yin) - & gt; & Lt; / Div & gt; & Lt; Div id = "description" & gt; & Lt ;! - Loop ('yaaaa', 'bbbbbb' for yin) - & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;   

I can take the click function in a named function and just pass through the arrays.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -