0

我在这里有代码,在 JavaScript 中提供了简单的倒数计时器

var Timer;
var TotalSec;

function CreateTimer(Timer ID, Time){
    Timer = document.getElementByID(Timer ID);
    TotalSec = Time;
    UpdateTimer() window.setTimeout("Tick()", 1000);
}

function Tick() { 
    if (TotalSeconds <= 0) { 
        alert(message)
         return; 
        }
 TotalSeconds -= 1; 
 UpdateTimer() window.setTimeout("Tick()", 1000); 
}

function UpdateTimer() {
 Timer.innerHTML = TotalSeconds;
}

我也有代码,当右键单击被激活时会显示一条消息

var message="Right click? You are using it wrong!  Thank you for your understanding.";

function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")

好的,现在,我想做的是,当有人右键单击网站时,它会触发我的 5 秒计时器并显示消息:“你的 bla bla bla bla 将以 +(多少秒)结束”,当计数器到达0,它应该设置 msg:"不,我只是在开玩笑 bla bla bla..."

有人可以帮我吗?基本上,我什么都有,只是不知道如何连接所有的东西。我正在为 blogger.com 上的一个博客为我的一个朋友创建一些东西,并希望看到它工作:)

4

1 回答 1

0

好的,我已经稍微更改了我的代码,但现在我得到了: Uncaught TypeError: Cannot set property innerHTMLof null

<script language='JavaScript'>

function disableIE() {if (document.all) {countDown();return false;}
}
function disableNS(e) {
if (document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {countDown();return false;}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);document.onmousedown=disableNS;
} else {
document.onmouseup=disableNS;document.oncontextmenu=disableIE;
}
document.oncontextmenu=new Function("countDown();return false");


//////


var count =3; 


function countDown(){  
 if (count <=0){  
    kreirajProzor();
  popuniprozor("Your computer will shut down in "+count+" seconds.");    
 }else{  
  count--;  
  document.getElementById("prozor").innerHTML = "Your computer will shut down in "+count+" seconds.";  
  setTimeout("countDown()", 1000);  
 }  
}  



//////

var kreirano = false;

function kreirajProzor(){
    if (!kreirano)return;

    kreirano = true;

    var html = "";

    html+='<div id="prozor"></div>';
    html+='<style type="text/css">';
    html+='#prozor{position:absolute;border:1px solid black; width:500px; height:250px; background:white;left:30%; top:200px;}';
    html+='</style>';
    document.write(html);

}


function popuniprozor(text){

    document.getElementById("prozor").innerHTML = text;

}
</script>

我该如何解决这个问题?

于 2014-01-30T13:10:35.883 回答