javascript - HTML Javascript 字体大小更改

标签 javascript html fonts

<html>
<head>
  <meta charset="utf-8">
  <script>
    function test(){
      var name = document.getElementById('name').value;
      var snumber = document.getElementById('snumber').value;
      document.write("name="+name+"");
      document.write("&snumber="+snumber+"<br />");
    }
  </script>
</head>

<body>
   <h2>Example of sending data using POST</h2>
     Name :
   <input type="text" id="name"><br/>
     Student number:
   <input type="text" id="snumber"><br/><br/>
   <input type="button" value="submit" onclick="test();">
</body>
</html>

我想将第6行和第7行结果的字体大小更改为h2大小 我可以通过放置

来更改正文部分
 <h2></h2> 

但是,它在脚本部分不起作用。如果我在 name 和 snumber 部分输入数据,它会连接到一个新页面,显示类似“name=David&snum=21467564”的输入,我希望此字体大小为 h2 大小!

最佳答案

只需添加 h2标签

单行输出:

function test(){
      var name = document.getElementById('name').value;
      var snumber = document.getElementById('snumber').value;
    
 document.write("<h2>name="+name+"");
 document.write("&snumber="+snumber+"</h2> <br/>");
 }
<h2>Example of sending data using POST</h2>
     Name :
   <input type="text" id="name"><br/>
     Student number:
   <input type="text" id="snumber"><br/><br/>
   <input type="button" value="submit" onclick="test();">

对于多行输出:只需关闭 <h2>标记并开始新的标题标记,例如:

document.write("<h2>name="+name+"</h2>");
document.write("<h2>snumber="+snumber+"</h2><br />");

关于javascript - HTML Javascript 字体大小更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44904736/

相关文章:

javascript - if 语句, $(this) == $ ("#div")

javascript - 如何禁用 &lt;input&gt; 提交但不输入

ios - 如何在 iOS 9 中使用新的 San Francisco 字体?

css - 是什么决定了在浏览器中显示的默认字体?

javascript - 针对发布商的 Google 消费者调查无效

JavaScript 正则表达式 : dynamic capture group

javascript - 通过Javascript设置输入框值

html - 是否可以仅根据其一个子项的宽度来调整容器的大小?

javascript - 弹性索引.html 模板

css - 自定义字体无法在 Chrome/Safari 中呈现