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