私は現在ウェブサイトに取り組んでいます。ページをロードするとカウントダウンが始まり、15秒後にボタンが表示されます。
現在、テストサーバーとjsFiddleで完全に機能します。ただし、Webサーバーに移動すると機能しません。Google Chromeのコンソールを調べたところ、次のエラーが発生しました。
downloadButton.parentNode.replaceChild(newElement, downloadButton);
Uncaught TypeError: Cannot read property 'parentNode' of null
これが完全なコードです(jsFiddle http://jsfiddle.net/6zchq/も参照してください)
var downloadButton = document.getElementById('download');
var counter = 15;
var newElement = document.createElement('p');
newElement.innerHTML = 'Getting your file, please wait 15 seconds.';
var id;
downloadButton.parentNode.replaceChild(newElement, downloadButton);
id = setInterval(function() {
counter--;
if(counter < 0) {
newElement.parentNode.replaceChild(downloadButton, newElement);
clearInterval(id);
} else {
newElement.innerHTML = "Getting your file, please wait " + counter.toString() + " seconds.";
}
}, 1000);
これは単純な問題だと確信しています。なぜ機能しないのか理解できません。
どんな助けでも大歓迎です!
ありがとう。