index.html的Pastebin:http://pastebin.com/kdKFqTxe 只需复制并粘贴并运行它(此工作但有一些损坏的图像链接& no css)。 关于pastebin,只需点击一个节点,然后点击视频下方第一个破碎的图像。应该发生什么是一个对话框应该出现链接到文章(从tubeArray)。所有相关的代码都粘贴在下面。根据数组中的数组更改div的内容
我试图动态更改div的内容,当我点击图像。图像具有相应的id(内部数组中的第一个索引),第一个内部数组中有另一个数组(索引3)。我想用点击图像时使用JQuery的链接来填充div(id =“articleLinks”)。
的JavaScript & JQuery的:
的管阵列。 *注意:tubeArray中每个元素的第一个索引是ID &新闻文章没有链接到任何特定的东西。只关心tubeArray [0] & tubeArray [4]
var tubeArray = [
['UQ', -27.495134, 153.013502, "http://www.youtube.com/embed/uZ2SWWDt8Wg",
[
["example.com", "Brisbane students protest university fee hikes"],
["example.com", "Angry protests over UQ student union election"],
]
],
['New York', 40.715520, -74.002036, "http://www.youtube.com/embed/JG0wmXyi-Mw",
[
["example.com" , "NY taxpayers’ risky Wall Street bet: Why the comptroller race matters"]
]
],
['To The Skies', 47.09399, 15.40548, "http://www.youtube.com/embed/tfEjTgUmeWw",
[
["example.com","Battle for Kobane intensifies as Islamic State uses car bombs, Syrian fighters execute captives"],
["example.com","Jihadists take heavy losses in battle for Syria's Kobane"]
]
],
['Fallujah', 33.101509, 44.047308, "http://www.youtube.com/embed/V2EOMzZsTrE",
[
["example.com","Video captures family cat saving California boy from dog attack"],
["example.com","Fines of £20,000 for dogs that chase the postman"]
]
]
];
一种用于环路经过在tubeArray每个元素然后分配ID到第一索引。另外一个图像,调用功能myFunctionId它采取参数this.id。
for (i = 0; i < tubeArray.length; i++) {
var id = tubeArray[i][0];
//other code
'<img src="img.png" onclick="myFunctionId(this.id);" id="' + id + '">' +
//other code
}
function myFunctionId (id) {
journal = id;
alert(journal) //just a test
//I want to search through tubeArray with the id and find the matching inner array.
//I then want to loop through the innerArray and append to my html a link using JQuery.
$('#articleLinks').append("<a href='"+innerArray[0]+"'>"+innerArray[1]+'</a>'); // use CSS to break lines
}
}
HTML:
<div id="articleLinks">
<a href="http:/www.google.com">Example Link</a><br>
</div>
任何帮助将不胜感激。我试图尽可能简化&,以便它可读。
与pastebin ...什么......有这么多事情发生。我点击了什么?我想要发生什么? – 2014-10-20 01:28:56
顶级黑色条令人难以置信的烦人,顺便说一句。 – 2014-10-20 01:30:07
有了所有这些代码,人们究竟做了什么来触发这个动作(你点击了什么),你想在点击上发生什么,以及它现在到底做了什么?你需要记住,我们对你想要做什么或你的页面如何工作一无所知。 – jfriend00 2014-10-20 01:30:15