<p>{&quot;title&quot;:&quot;继续上一个问题&quot;,&quot;description&quot;:&quot;<script>\n\nvar s ='5102';\nif(s==&quot;5101&quot;){\n   s = &quot;零售&quot;;\n}else if(s==&quot;5102&quot;){\n   s = &quot;零售(连锁)&quot;;\n}\n document.write(s);\n</script>\n它里面的样式是这样的  我该怎么写能让他出来数据&quot;,&quot;keywords&quot;:&quot;javascript, 变量, 数据, 显示, 网页, html, innerHTML, getElementById&quot;,&quot;content&quot;:&quot;要让脚本中的数据显示在页面上,你可以在HTML中添加一个元素,然后使用JavaScript将数据写入该元素。例如,你可以在页面中添加一个<code>&lt;div&gt;</code>元素,并为其设置一个唯一的ID,然后在脚本中使用<code>document.getElementById()</code>方法获取该元素,并使用<code>innerHTML</code>属性将数据写入该元素。\n\nHTML代码示例:\n\n<code>html\n&lt;div id=&quot;result&quot;&gt;&lt;/div&gt;\n</code>\n\nJavaScript代码示例:\n\n<code>javascript\nvar s ='5102';\nif(s==&quot;5101&quot;){\n   s = &quot;零售&quot;;\n}else if(s==&quot;5102&quot;){\n   s = &quot;零售(连锁)&quot;;\n}\ndocument.getElementById(&quot;result&quot;).innerHTML = s;\n</code>\n\n这样,脚本中的数据就会显示在具有ID为&quot;result&quot;的<code>&lt;div&gt;</code>元素中。&quot;}</p>
如何将JavaScript变量数据显示在网页上

原文地址: https://www.cveoy.top/t/topic/pPlA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录