必要はありませんjQueryの。これをヘッダーに入れてください。 10000ミリ秒、または10秒後にhistory.go(-1)
を呼び出します。
<script type="text/javascript">
setTimeout(function() {
history.go(-1);
}), 10000);
</script>
ボタンにタイマーが欲しいと気付きました。これは少しjQueryを使うことができます。あなたがそれにいる間、あなたのインラインJavaScriptのonclick="javascript:..."
をあなたのスクリプト本体に移すべきです。インラインのjavascriptは好意を失っています。主な理由は、操作が面倒なことです。
<script type="text/javascript">
$(function() {
// While you are at it, remove do the click handler here:
$(document).on('click', '.button', function() {
history.go(-1);
})
// Get button name, init timer value
var buttonName = $('.button').val();
var time = 10;
function updateButton() {
// Set button name to "Go back to previus page (X)"
$('.button').val(buttonName+' ('+time+')');
if(time <= 0) {
// If we reached 0, redirect
history.go(-1);
} else {
//decrement time counter
time--;
// otherwise, wait a second and do it again
setTimeout(updateButton, 1000);
}
}
// Start the counter
updateButton();
});
</script>
またsetInterval()
を使用することができますが、このみましょうあなたは少し簡単に時間0で、ボタンのタイマーを設定します。
例:dku.rajkumar @http://jsfiddle.net/jtbowden/gJsPw/
私はそれを行うことができますどのように? – Drazek
あなたの古い質問のいくつかに最適な答えを "受け入れ"ます。 – Sparky
@ Sparky672チップのおかげでやります。 – Drazek