我是编程新手,我有一个关于如何把一些东西放在一起的问题。
我这里的代码,在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:“不,我只是开玩笑吧......”
是的,有人可以帮帮我吗?基本上,我有一切,只是不要{blog}在博客网站上为我的朋友创建一些博客,并希望看到它有效:)答案 0 :(得分:0)
好的我已经改变了我的代码,但现在我得到了: 未捕获的TypeError:无法设置null
的属性innerHTML
<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>
我该如何解决这个问题?