在html正文中显示javascript变量

编程入门 行业动态 更新时间:2024-10-20 07:56:54
本文介绍了在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变量

本文发布于:2023-10-12 23:56:31,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文中   变量   html   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!