我在表格中有以下条目:
function clickCounter() {
if (typeof (Storage) !== "undefined") {
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount) + 1;
} else {
localStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = localStorage.clickcount;
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
}
}
document.getElementById("result").innerHTML = localStorage.clickcount;
function addCounter() {
if (typeof (Storage) !== "undefined") {
if (localStorage.clickcounts) {
localStorage.clickcounts = Number(localStorage.clickcounts) + 1;
} else {
localStorage.clickcounts = 1;
}
document.getElementById("result2").innerHTML = localStorage.clickcounts;
} else {
document.getElementById("result2").innerHTML = "Sorry, your browser does not support web storage...";
}
}
document.getElementById("result2").innerHTML = localStorage.clickcounts;
以及以下javascript:
for (int k = 0; k < proc.Count; k++){
for (int i = k + 1; i < proc.Count; i++){
bool doSwap = false;
if (proc[k].arrivalTime > proc[i].arrivalTime)
{
doSwap = true;
}
else if (proc[k].arrivalTime == proc[i].arrivalTime)
{
if(proc[k].priority > proc[i].priority)
{
doSwap = true;
}
else if (proc[k].priority == proc[i].priority )
{
if(proc[k].brust > proc[i].brust)
{
doSwap = true;
}
}
}
if(doSwap)
{
temp = proc[i];
proc[i] = proc[k];
proc[k] = temp;
}
}
}
我希望两个计数器始终显示在屏幕上,即使刷新页面后也无需按按钮查看值。我已经使用了表中的这些代码,它们工作正常。任何人都可以帮我理解为什么计数器不会一直显示在屏幕上?
答案 0 :(得分:1)
Div元素没有load
个事件。只有从其他网址(如图片和框架)和文档本身获取内容的元素才会这样做。
因为您正在使用内部事件属性([虽然有问题](Why can't I call a function named clear from an onclick attribute? )),如果您使用过a validator,那么这将被取消。
或者:
答案 1 :(得分:1)
onload()
事件不能用于任何其他元素,只能使用一组有限的标记:<body>
<frame>
<frameset>
<iframe>
<img>
{ {1}} <link>