HTML教程
HTML5教程
HTML参考手册

如何在HTML中调用JavaScript函数?

如果我们要在HTML中调用JavaScript函数,则必须遵循以下步骤。使用这些步骤,我们可以轻松访问JavaScript函数。
第1步:首先,我们必须在标题后面的 <head>标记 的开始和结束之间键入脚本标记。标签。然后,输入JavaScript函数。
<Head>
<Title>
Call a JavaScript function
</Title>
<script type = "text/javascript">
  function msgprint() {
    alert("You are Successfully Called the JavaScript function");
  }
</script>
</Head>
第2步:之后,我们必须在 HTML 中调用javaScript函数>用于在网页上显示信息或数据的代码。因此,我们可以在表单标签的输入标签中通过其名称来调用JavaScript函数。
<form> input type = "button" onclick = "msgprint()" value = "Message Print"></form>
第3步:最后,我们必须保存Html文件,然后运行调用JavaScript函数的文件。
<!Doctype Html>
<Html>
<Head>
<Title>
Call a JavaScript function
</Title>
<script type = "text/javascript">
         function msgprint() {
            alert("You are Successfully Called the JavaScript function");
         }
</script>
</Head>
<Body>
<p>Click on the following button for calling the function: </p>
      <form>
         <input type = "button" onclick = "msgprint()" value = "Message Print">
      </form>
      <p>
</Body>
</Html>
上述HTML代码的输出显示在以下屏幕截图中:
如何在HTML中调用JavaScript函数
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4