0

この画像http://svastara.info/.s/img/icon/download1.pngをDownload nowの前に移動するにはどうすればよいですか? image今すぐダウンロード

var CountdownTimer = function( id, count, imgurl ) { this.construct(id, count, imgurl); }
CountdownTimer.prototype = {
        construct: function(id,count,imgurl) {
                this.id = id;
                this.object = document.getElementById(id);
                this.count = count;
                this.interval = null;
                this.counted = false;
                this.img = new Image(); // preload
                this.img.src =  imgurl;
                this.img.border = "0";

                (function(obj) {
                        obj.object.onclick = function() {
                                return obj.onclick();
                        };
                })(this);
        },

        tick: function() {
                this.count--;
                this.render();

                if(this.count == 0){ 
                        clearInterval(this.interval);
                        this.interval = null;
                        this.object.appendChild(this.img);
                }
        },

        onclick: function() {
                if(!this.counted) {
                        this.counted = true;
                        this.render();
                        (function(obj) {
                                obj.interval = setInterval(function() {
                                        obj.tick();
                                },1000);
                        })(this);
                        return false;
                } else if(this.count == 0)
                        return true;
                else
                        return false;
        },

        render: function() {
                if(this.count > 0)
                        this.object.innerHTML = "Download (" + this.count + " second" + (this.count == 1 ? "" : "s") + ")";
                else
                        this.object.innerHTML = "Download Now";
        }

};

window.onload = function() {
        var c = new CountdownTimer("delayed",3,"http://svastara.info/.s/img/icon/download1.png");
};

<div>
<a id="delayed" class="stop" href="http://www.epiclosers.com/">Download (30sec)</a>
</div>
4

1 に答える 1

0

insertBefore メソッドを見てください。既存のテキストはアンカー タグの子ノードである必要があります。

そうは言っても、なぜ人々はここで派手なことをしているのだろうと思い始めています... あなたはユニークではありません。HTML と CSS を使用できるようにすることで、コードを単純化できます。ドキュメントに画像を配置し、表示をなしに設定し、必要なときにオンにします。また、ダウンロード後のテキストは、必要に応じて更新されるスパンにすることもできます。そうすれば、ほんの一部のコードですべてを管理できます。単純化に関する最終的な考えとして、許可する準備が整うまでリンクを無効にすることができます。

また、クライアントで単純なデバッガーを使用して、その場でカウントを 0 に変更し、ロジックを完全にバイパスすることができます。または、さらに簡単に、javascript をオフにしてリンクをクリックすることもできます。つまり、クライアントにはない他の手段で強制していることを確認してください。ポリシーの強制をクライアントに依存するのは常に悪い考えなので、サーバー側でバックアップしてください。あなたはそうしているかもしれませんので、コメントに腹を立てないでください。

于 2009-09-28T03:26:15.227 に答える