本文主要是介绍在JSP页面中获取JavaScript中var变量的值,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在js中用var声明变量后并赋值(假设这个值为字符串"variable"),这个值
如果需要在JSP中拿出来显示可以使用此方法:
先在JSP中写一个span标签并设置ID,回到刚刚声明变量的js中在下面补上一句
span_id.innerHTML=variable
在页面中你想要显示此变量值得位置加上<span id="span_id"></span>即可
DEMO:
<script language="JavaScript">function tick() {var hours, minutes, seconds;var intHours, intMinutes, intSeconds;var today;today = new Date();intHours = today.getHours();intMinutes = today.getMinutes();intSeconds = today.getSeconds();if (intHours == 0) {hours = "00:";} else if (intHours < 10) {hours = "0" + intHours+":";} else {hours = intHours + ":";}if (intMinutes < 10) {minutes = "0"+intMinutes+":";} else {minutes = intMinutes+":";}if (intSeconds < 10) {seconds = "0"+intSeconds+" ";} else {seconds = intSeconds+" ";}timeString = hours+minutes+seconds;Clock.innerHTML = timeString;window.setTimeout("tick();", 1000);}window.onload = tick; </script> <div><p align="center">XXXX页面 2019年11月9日 <span id="DTime"></span> <span id="Clock"></span> <strong>信息部-</strong>技术支持 <font color="#FF0000">Ver 0.0.1 </font></p> </div> <script type="text/javascript">var strDateTime ="星期"+"日一二三四五六".charAt(new Date().getDay());DTime.innerHTML=strDateTime; </script>
这篇关于在JSP页面中获取JavaScript中var变量的值的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!