मैं अपने ब्लॉग का संग्रह अनुभाग में एक महीने के विस्तार देखा गया लोड करने के लिए दो कार्य बना लिया है, जब यह लिंक पर क्लिक किया जाता है:क्या एलेमेंटबीआईआईडी जावास्क्रिप्ट द्वारा बनाए गए तत्वों पर काम करता है?
// Load open view of a month in the Archive section
function loadMonth(date) {
// Remove other open month
removeMonth();
// Hide opening month's link
// Define variable to hold month anchor tag
var monthLink = document.getElementById(date);
monthLink.style.display = "none"; // Hide month anchor
// Define new open month node and its attributes
var openMonth = document.createElement("div");
openMonth.setAttribute("id", "openMonth");
openMonth.innerHTML = "Testing one, two, three.";
// Insert open month
// Define a variable to hold the archive Div node
var archive = document.getElementById("archive");
// Insert the open month in the archive node before it's link
archive.insertBefore(openMonth,monthLink);
return;
}
// Close full view of a month and replace with respective link
function removeMonth() {
// Define global function vars
var archive = document.getElementById("archive"); // Define a var to hold the archive Div node
var openMonth = document.getElementById("openMonth"); // Define var to hold the open month Div node
// Get date of full view month for replacement anchor tag where ID = date
var month = openMonth.getElementsByTagName("span")[0].innerHTML; // Define var to hold the name of the open month
var date = (new Date(month + " 15, 2008").getMonth() + 1); // Define var to hold the numerical equivalent of the month
var year = archive.getElementsByTagName("h3")[0].innerHTML.split(" "); // Define var to hold the year being displayed in the archive
date = year[1] + "" + date; // Change date var to string and insert year
// Remove the open month
archive.removeChild(openMonth);
// Show Link for that month
document.getElementById(date).className = "big"; // Fixes display error when anchor has class firstLink
document.getElementById(date).style.display = "inline"; // Returns link from display "none" state
return;
}
फ़ंक्शन कार्य जब मूल स्थैतिक सामग्री पर चलने, लेकिन जब एक दूसरे लिंक संग्रह में क्लिक किया गया है, वे कुछ भी नहीं करते हैं। मैं सोच रहा हूं कि शायद इसलिए कि मेरे कार्यों द्वारा बनाए गए तत्वों को document.getElementById द्वारा नहीं बुलाया जा सकता है। शायद उन नोड्स तक पहुंचने का एक अलग तरीका इस्तेमाल किया जाना चाहिए, या हो सकता है कि "दस्तावेज़" को किसी ऐसे चीज़ से बदल दें जो जावास्क्रिप्ट पर बनाए गए तत्वों पर भी काम करता हो?
किसी भी सलाह की सराहना की जाएगी। धन्यवाद।
(जैसे कि समस्या से पता चलता) कहीं (उदाहरण के लिए यहाँ http://pastebin.me/) मदद की आप अपने कोड की एक काम उदाहरण पोस्ट कर सकते हैं? आपका कोड देखकर, मेरा मानना है कि आपके दृष्टिकोण में एक सामान्य गलतफहमी है। – Tomalak