Implementation Code for Getting Page Document Content with JavaScript

  • 2021-06-28 08:39:18
  • OfStack

The document object of JavaScript contains the actual content of the page, so the document object can be used to obtain the content of the page, such as the page title, individual form values.


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>js Basics </title>

</head>

<body>
<p>1.  use Document Object gets page title </p>
<hr/>
<p>2.  use Document Visit 1 Next two forms </p>

<p> No. 1 , the value of the text box </p>

<form name="textform">
  <input name="textname" type="text" value=" Please enter text "/>
</form>
<p> No. 2 Number of buttons </p>

<form name="submitform">
  <input name="submitname" type="submit" value=" No. 1 Submitted within forms "/>
</form>
<hr/>
<p> The following values are obtained </p>
<table border="1" cellspacing="4" cellpadding="2">
  <tr>
    <td> The title that gets to this page is   :  </td>
    <td> <b><script>document.write(document.title)</script></b></td>
  </tr>
  <tr>
    <td> This page contains forms   :  </td>
    <td><b><script>document.write(document.forms.length)</script></b></td>
  </tr>
  <tr>
    <td> Get the value of the text box   :  </td>
    <td><b><script>document.write(window.document.textform.textname.value)</script></b></td>
  </tr>
  <tr>
    <td> Get the value of the button   :  </td>
    <td><b><script>document.write(window.document.submitform.submitname.value)</script></b></td>
  </tr>

</table>

</body>
</html>

Related articles: