⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 17.14.htm

📁 这是我卖的书上的源码 这书是电子邮电出版的是有关网络编程 有详细的例子
💻 HTM
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Dynamic Form Demo</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<script type="text/javascript">
<!--
// Set up form variables and constants
var widgetCost = 1.50;
var gadgetCost = 2.70;
var thingieCost = 1.25;
var taxRate = 0.075;
var shippingCost = 0;

function isNumberInput(field, event) 
{
  var key, keyChar;

  if (window.event)
    key = window.event.keyCode;
  else if (event)
    key = event.which;
  else
    return true;

  // Check for special characters like backspace
  if (key == null || key == 0 || key == 8 || key == 13 || key == 27)
    return true;

  // Check to see if it.s a number
  keyChar =  String.fromCharCode(key);

  if (/\d/.test(keyChar))
   {
    window.status = "";
    return true;
   } 
  else 
  {
    window.status = "Field accepts numbers only.";
    return false;
  }
}

function format(value)
{
  // Format to have only two decimal digits
  var temp =  Math.round(value * 100);
  temp = temp / 100;
  return temp;
}

function calc()
{
  with (document.myform)
  {
    widgettotal.value = format(widgets.value * widgetCost);
    gadgettotal.value = format(gadgets.value * gadgetCost);
    thingietotal.value = format(thingies.value * thingieCost);
    subtotal.value = format(parseFloat(widgettotal.value) +
                            parseFloat(gadgettotal.value) +
                            parseFloat(thingietotal.value));
    tax.value = format(subtotal.value * taxRate);

    for (i=0; i < shipping.length; i++)
      if (shipping[i].checked)
        shippingcost = parseFloat(shipping[i].value);

    grandtotal.value = format(parseFloat(subtotal.value) +
                              parseFloat(tax.value) +
                              shippingcost);
  }
}
//-->
</script>
</head>
<body>
<center><h1>动态表单测试</h1></center>
<form id="myform" name="myform" action="#" method="get">
Widgets: <input type="text" name="widgets" id="widgets"
          size="2" value="0" onchange="calc();"
          onkeypress="return isNumberInput(this, event);">
         @ 1.50 each
<input type="text" id="widgettotal" name="widgettotal"
       size="5" readonly="readonly">
<br>
Gadgets: <input type="text" name="gadgets" id="gadgets"
          size="2" value="0" onchange="calc();"
          onkeypress="return isNumberInput(this, event);">
         @ 2.70 each
<input type="text" id="gadgettotal" name="gadgettotal"
       size="5" readonly="readonly">
 <br>
Thingies: <input type="text" name="thingies" id="thingies"
           size="2" value="0" onchange="calc();"
           onkeypress="return isNumberInput(this, event);">
          @ 1.25 each
<input type="text" id="thingietotal" name="thingietotal"
       size="5" readonly="readonly">
 <br><br><br>
<em>Subtotal:</em> 
<input type="text" id="subtotal"
       name="subtotal" size="8" value="0" readonly="readonly">
<br><br><br>
<em>Tax:</em> <input type="text" id="tax" name="tax" size="5"
               value="0" readonly="readonly">
<br><br><br>
<em>Shipping:</em>
Next day: <input type="radio" value="12.00" name="shipping"
           id="shipping" checked="true" onclick="calc();">
2-day: <input type="radio" value="7.00" name="shipping"
        id="shipping" onclick="calc();">
Standard: <input type="radio" value="3.00" name="shipping"
           id="shipping" onclick="calc();">
<br><br><br>
<strong>Grand Total:</strong>
<input type="text" id="grandtotal" name="grandtotal"
 size="8" readonly="readonly">
</form>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -