的问题是,几乎所有在createWrapp
您的变数是暗示全球。对clock()
的连续调用将覆盖它们,并且只有最后创建的时钟打勾。使用var
statements!
将其更改为:
function clock() {
var outerDiv = createElementWithClass('div', 'clock-window-wrapper'),
innerDiv = createElementWithClass('div', 'clock-menubar-wrapper');
outerDiv.appendChild(innerDiv);
document.getElementById("page-content-wrapper").appendChild(outerDiv);
var clock_windows_wrapper_close = createElementWithClass('div', 'close');
innerDiv.appendChild(clock_windows_wrapper_close);
var clock_toolbar_wrapper_close = createElementWithClass('div', 'clock-content-wrapper');
outerDiv.appendChild(clock_toolbar_wrapper_close);
var hours = createElementWithClass('ul', 'clock-digit-wrapper hour');
clock_toolbar_wrapper_close.appendChild(hours);
clock_toolbar_wrapper_close.appendChild(document.createTextNode(' ')); // Add this ##WTF
var minutes = createElementWithClass('ul', 'clock-digit-wrapper minute');
clock_toolbar_wrapper_close.appendChild(minutes);
clock_toolbar_wrapper_close.appendChild(document.createTextNode(' ')); // And this ##
var seconds = createElementWithClass('ul', 'clock-digit-wrapper second');
clock_toolbar_wrapper_close.appendChild(seconds);
var hour1 = createElementWithClass('li', "clock-digit-four");
var hour2 = createElementWithClass('li', "clock-digit-one");
hours.appendChild(hour1);
hours.appendChild(hour2);
var minute1 = createElementWithClass('li', "clock-digit-three");
var minute2 = createElementWithClass('li', "clock-digit-three");
minutes.appendChild(minute1);
minutes.appendChild(minute2);
var sec1 = createElementWithClass('li', "clock-digit-three");
var sec2 = createElementWithClass('li', "clock-digit-seven");
seconds.appendChild(sec1);
seconds.appendChild(sec2);
createWrapp
作为一个独立的功能实际上是没有必要的,因为它仅调用一次,没有变量是本地的。
请在这里发布您的实际代码。 – Bergi 2013-02-13 00:06:28