javascript to jsp [英] javascript to jsp
问题描述
...
<脚本类型> 如何在jsp中显示javascript'var'? = 文本/ JavaScript的 >
... //我的代码来获取值。
var val = combo.getValue();
< / script>
< body>
值为://在此处显示
< / body>
添加一个HTML元素,值将被显示并给它一个 id
。
<体>
值为:< span id =value>< / span>
< / body>
然后让JS通过 document.getElementById()
并修改其内部HTML。
document.getElementById(value)。innerHTML = val;
您只需确保在加载HTML页面后执行特定脚本。在 window.onload
期间或者在结束时放置
或者将它包装在< script>
< body> 函数
中,您可以在某个事件上执行。
至于JSP部分,这里并不相关。所有的JSP都会生成并发送HTML / CSS / JS代码,从web服务器到webbrowser。 JavaScript对JSP一无所知,它可以看到并访问的是HTML / CSS,您可以通过右键单击webbrowser中的页面并选择查看源代码来查看HTML / CSS。
另见:
How to show a javascript 'var' in my jsp?
...
<script type="text/javascript">
... // My code to get the value.
var val = combo.getValue();
</script>
<body>
The value is : //to be displayed here
</body>
Add a HTML element which should mark the place where the value is to be displayed and give it an id
.
<body>
The value is : <span id="value"></span>
</body>
Then let your JS access it by document.getElementById()
and modify its inner HTML.
document.getElementById("value").innerHTML = val;
You only need to ensure that the particular script executes after the HTML page has loaded. Do it during window.onload
or put the <script>
at end of <body>
or wrap it in a function
which you execute on some event.
As to the JSP part, this is not relevant here. All JSP does is generating and sending HTML/CSS/JS code from webserver to webbrowser. JavaScript knows nothing about JSP, all it can see and access is HTML/CSS which you can also see by rightclicking the page in webbrowser and choosing View Source.
See also:
这篇关于javascript to jsp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!