【发布时间】:2014-10-20 10:06:05
【问题描述】:
index.html的Pastebin:http://pastebin.com/kdKFqTxe 只需复制并粘贴并运行它(这可行,但有一些损坏的 img 链接且没有 css)。 关于 pastebin,只需单击一个节点,然后单击视频下方的第一个损坏的图像。应该会出现一个对话框,其中包含文章链接(来自 tubeArray)。所有相关代码都粘贴在下面。
我试图在单击图像时动态更改 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 中每个元素的 for 循环,然后将 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...什么...发生了很多事情。我在点击什么?我想要发生什么?
-
顶部的黑条实在是太烦人了,顺便说一句。
-
使用所有这些代码,究竟是做什么来触发动作(你点击什么),你到底想在点击时发生什么以及它现在到底在做什么?您需要记住,我们对您想要做什么或您的页面如何运作一无所知。
-
将您的代码缩减为一个最小的示例,并将其与复制步骤和期望一起放入 jsfiddle.net
-
我认为...我们点击红点。不确定。
标签: javascript jquery html css arrays