简体   繁体   English

在运行时编辑Javascript并影响HTML页面上的计时器

[英]Edit Javascript and affect timer on HTML page in runtime

I am trying to skip timer placed on an HTLM page. 我试图跳过放置在HTLM页面上的计时器。 Javascript for the TIMER is below: TIMER的Javascript如下:

var t = 60;
var decr = 1;
var handle = null;
var e = null;
function startTimer() {
    if(!e) e = document.getElementById("time");
    e.innerHTML = t;
    handle = setInterval(function() {
        if(t == 0) {
            clearInterval(handle);
            var answer = confirm("Yes/No?")
            if (answer){
                alert("You Clicked Yes!")
                window.location = "https://twitter.com/";
            }
            else{
                alert("You Clicked No!")
            }
        }
        else {
            t -= decr;
            e.innerHTML = t;
        }
    }, decr * 1000);
}
window.onload = startTimer;

What I want is to change the TIMER to 10 seconds as soon as the page gets loaded. 我要的是在页面加载后立即将TIMER更改为10秒。 I tried to enter the following code in browser location bar: 我试图在浏览器位置栏中输入以下代码:

javascript:document.getElementById('time').innerHTML = "10";

But I'm not getting into it. 但是我不喜欢它。 What'll be the proper way to do it? 正确的做法是什么?

Open the console (development tools). 打开控制台(开发工具)。 If you are using chrome, press F12, then press console and insert the command 如果您使用的是chrome,请按F12,然后按console并插入命令

document.getElementById('time').innerHTML = "10";

or 要么

document.getElementById('time').value = "10";

and then press enter. 然后按Enter。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM