Java脚本没有调用html

时间:2016-05-18 10:24:40

标签: javascript html

java脚本代码,它有两个函数display()和DisplaySessionTimeout()。

 <script type="text/javascript">
            var sessionTimeout = 1800;

            function DisplaySessionTimeout()
            {
                window.history.go(+1);
                sessionTimeout = sessionTimeout - 1;
                //document.getElementById("val").innerHTML=sessionTimeout;

                //if session is not less than 0
                if (sessionTimeout >= 0)
                {
                    //call the function again after 1 minute delay

                    window.setTimeout("DisplaySessionTimeout()", 1000);
                } else
                {
                    //show message box
                    //document.getElementById("val").innerHTML="TIME OUT";
                    alert("Your current Session is over.");
                    setTimeout(document.form1.sub.click());
                }
            }


            

                    var milisec = 0
            var seconds = 30
            document.form1.d2.value = '30'

            function display()
            {
                if (milisec <= 0) {
                    milisec = 60
                    seconds -= 1
                }
                if (seconds <= -1) {
                    milisec = 0
                    seconds += 1
                } else
                    milisec -= 1
                document.form1.d2.value = seconds + "M : " + milisec + " S"
                setTimeout("display()", 1000)
            }

         
        </script>
  <body onLoad="javascript:display();DisplaySessionTimeout();">

html的body部分调用java脚本,但它不起作用。为什么它不起作用?关于如何使其发挥作用的任何想法?

1 个答案:

答案 0 :(得分:0)

我编辑了一些内容,例如从Js中删除了html-comment语句,从JavaScript:删除onload等等。

html中的评论:<!-- comment -->

JS中的评论:

//comment single line
/*
   Comment multi-line
*/

我认为这应该解决它。

var sessionTimeout = 1800;

function DisplaySessionTimeout() {
  window.history.go(+1);
  sessionTimeout = sessionTimeout - 1;
  //document.getElementById("val").innerHTML=sessionTimeout;

  //if session is not less than 0
  if (sessionTimeout >= 0) {
    //call the function again after 1 minute delay

    window.setTimeout("DisplaySessionTimeout()", 1000);
  } else {
    //show message box
    //document.getElementById("val").innerHTML="TIME OUT";
    alert("Your current Session is over.");
    setTimeout(document.form1.sub.click());
  }
}



// 
var milisec = 0
var seconds = 30
document.form1.d2.value = '30'

function display() {
  if (milisec <= 0) {
    milisec = 60
    seconds -= 1
  }
  if (seconds <= -1) {
    milisec = 0
    seconds += 1
  } else
    milisec -= 1
  document.form1.d2.value = seconds + "M : " + milisec + " S"
  setTimeout("display()", 1000)
}
<body onload="display();DisplaySessionTimeout();">

如果您仍然收到错误,请发布完整代码,以便我查看。