JavaScript DHTML/Language Basics/With

Материал из Web эксперт
Перейти к: навигация, поиск

Using the with Statement in JavaScript

 
<html>
<head>
  <title>JavaScript Unleashed</title>
</head>
<body>
  <script type="text/javascript">
  <!--
    with(document){
      write("Hello!");
      write("<br>The title of this document is, \"" + title + "\".");
      write("<br>The URL for this document is: " + URL);
      write("<br>Now you can avoid using the object"s prefix each time!");
    }
  // -->
  </script>
</body>
</html>



With statement

 
<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
inp1 = 1;
inp2 = 2;
inp3 = 3;
with (Math)
{
    alert("The largest number entered was " + max(inp1, inp2, inp3));
    alert("The smallest number entered was " + min(inp1, inp2, inp3));
}
</script>
</head>
<body>
</body>
</html>