Тег <legend></legend>




Этот тег определяет заголовок для элемента <fieldset></fieldset>.



Аргумент Значение
align left
center
right
title text




index.php
  • <?php
  • class Account {
  •  private $val0;
  •  private $val1;
  •  private $sign;
  •  function __construct($arg0, $arg1, $arg2) {
  •   $this->val0 = $arg0;
  •   $this->val1 = $arg1;
  •   $this->sign = $arg2;
  •  }
  •  function Res() {
  •   switch($this->sign) {
  •    case '' :
  •     return null;
  •    break;
  •    case '+' :
  •     return $this->val0 + $this->val1;
  •    break;
  •    case '-' :
  •     return $this->val0 - $this->val1;
  •    break;
  •    case '*' :
  •     return $this->val0 * $this->val1;
  •    break;
  •    case '/' :
  •     if($this->val1 == 0) {
  •      return 'You can not divide by zero!';
  •     }
  •     else {
  •      return $this->val0 / $this->val1;
  •     }
  •    break;
  •    case '%' :
  •     if($this->val1 == 0) {
  •      return 'You can not divide by zero!';
  •     }
  •     else {
  •      return $this->val0 % $this->val1;
  •     }
  •    break;
  •   }
  •  }
  • }
  • ?>
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  • </head>
  • <body>
  • <?php
  • if($_SERVER['REQUEST_METHOD'] == 'POST') {
  •  $val0 = (float)$_POST['val0'];
  •  $val1 = (float)$_POST['val1'];
  •  $sign = $_POST['sign'];
  •  $A = new Account($val0, $val1, $sign);
  •  $res = $A->Res();
  •  if($_REQUEST['clear']) {
  •   $val0 = null;
  •   $sign = null;
  •   $val1 = null;
  •   $res = null;
  •  }
  • }
  • ?>
  • <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
  •  <fieldset>
  •   <legend>The calculator</legend>
  •   <input type="text" name="val0" value="<?php echo $val0; ?>" />
  •   &nbsp;&nbsp;&nbsp;
  •   <select name="sign">
  •    <option value=""><?php echo $sign; ?></option>
  •    <option value="+">+</option>
  •    <option value="-">-</option>
  •    <option value="*">*</option>
  •    <option value="/">/</option>
  •    <option value="%">%</option>
  •   </select>
  •   &nbsp;&nbsp;&nbsp;
  •   <input type="text" name="val1" value="<?php echo $val1; ?>" />
  •   &nbsp;&nbsp;&nbsp;
  •   <input type="submit" name="perform" value="=" />
  •   &nbsp;&nbsp;&nbsp;
  •   <input type="text" name="res" value="<?php echo $res; ?>" />
  •   &nbsp;&nbsp;&nbsp;
  •   <input type="submit" name="clear" value="Clear" />
  •  </fieldset>
  •  <fieldset>
  •   <legend>The result</legend>
  •   <?php
  •   if($_SERVER['REQUEST_METHOD']=='POST' && $_REQUEST['perform'] && !$_REQUEST['clear']) {
  •    echo $val0, ' ', $sign, ' ', $val1, ' = ', $res;
  •   }
  •   else {
  •    echo null;
  •   }
  •   ?>
  •  </fieldset>
  • </form>
  • </body>
  • </html>
  • <?php
  • class Account {
  •  private $val0;
  •  private $val1;
  •  private $sign;
  •  function __construct($arg0, $arg1, $arg2) {
  •   $this->val0 = $arg0;
  •   $this->val1 = $arg1;
  •   $this->sign = $arg2;
  •  }
  •  function Res() {
  •   switch($this->sign) {
  •    case '' :
  •     return null;
  •    break;
  •    case '+' :
  •     return $this->val0 + $this->val1;
  •    break;
  •    case '-' :
  •     return $this->val0 - $this->val1;
  •    break;
  •    case '*' :
  •     return $this->val0 * $this->val1;
  •    break;
  •    case '/' :
  •     if($this->val1 == 0) {
  •      return 'You can not divide by zero!';
  •     }
  •     else {
  •      return $this->val0 / $this->val1;
  •     }
  •    break;
  •    case '%' :
  •     if($this->val1 == 0) {
  •      return 'You can not divide by zero!';
  •     }
  •     else {
  •      return $this->val0 % $this->val1;
  •     }
  •    break;
  •   }
  •  }
  • }
  • ?>
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  • </head>
  • <body>
  • <?php
  • if($_SERVER['REQUEST_METHOD'] == 'POST') {
  •  $val0 = (float)$_POST['val0'];
  •  $val1 = (float)$_POST['val1'];
  •  $sign = $_POST['sign'];
  •  $A = new Account($val0, $val1, $sign);
  •  $res = $A->Res();
  •  if($_REQUEST['clear']) {
  •   $val0 = null;
  •   $sign = null;
  •   $val1 = null;
  •   $res = null;
  •  }
  • }
  • ?>
  • <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
  •  <fieldset>
  •   <legend>The calculator</legend>
  •   <input type="text" name="val0" value="<?php echo $val0; ?>" />
  •   &nbsp;&nbsp;&nbsp;
  •   <select name="sign">
  •    <option value=""><?php echo $sign; ?></option>
  •    <option value="+">+</option>
  •    <option value="-">-</option>
  •    <option value="*">*</option>
  •    <option value="/">/</option>
  •    <option value="%">%</option>
  •   </select>
  •   &nbsp;&nbsp;&nbsp;
  •   <input type="text" name="val1" value="<?php echo $val1; ?>" />
  •   &nbsp;&nbsp;&nbsp;
  •   <input type="submit" name="perform" value="=" />
  •   &nbsp;&nbsp;&nbsp;
  •   <input type="text" name="res" value="<?php echo $res; ?>" />
  •   &nbsp;&nbsp;&nbsp;
  •   <input type="submit" name="clear" value="Clear" />
  •  </fieldset>
  •  <fieldset>
  •   <legend>The result</legend>
  •   <?php
  •   if($_SERVER['REQUEST_METHOD']=='POST' && $_REQUEST['perform'] && !$_REQUEST['clear']) {
  •    echo $val0, ' ', $sign, ' ', $val1, ' = ', $res;
  •   }
  •   else {
  •    echo null;
  •   }
  •   ?>
  •  </fieldset>
  • </form>
  • </body>
  • </html>