本文介绍了在html正文中显示javascript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是我的近似代码:
here is my approximate code:
<script> function smth(){........} var name = smth('fullname'); var hobby = smth('hobby'); </script>我需要在html正文中正常显示它。然而,我试过的每一种方式都给了我一个警戒窗口,或者根本不起作用。我没有找到类似的解决方案。 我知道上面的方式也给出了一个警告窗口,但我只是想告诉你我得到变量的方式。 在此先感谢。
I need to display it normally in the html body. However, every way I tried gave me an alert window or it simply didn't work. I didn't find the similar solution. I know that the way above gives an alert windows as well, but I just wanted to show you the way I get my variables. Thanks in advance.
推荐答案使用的innerHTML 。假设你在< body> 中声明一个< p> 作为输出,那么你可以这样写: p>
One of the very common ways to do this is using innerHTML. Suppose you declare a <p> in the <body> as output, then you can write:
<script> function smth(){........} var name=smth('fullname'); var hobby=smth('hobby') var out=document.getElementById("output"); out.innerHTML=name; (or you may write hobby) </script>更多推荐
在html正文中显示javascript变量
发布评论