日期:2014-05-16 浏览次数:20446 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>水果</title> <style type="text/css"> #a{ width:600px; height:300px; font-size:15px; color:white; position:absolute; top:100px; left:400px; background-color:blue; z-index:3; } </style> <script language="javascript"> document.onreadystatechange = function(){ if(document.readyState=="complete") { allElements=document.getElementsByTagName("input"); for (var i = 0; i < allElements.length; i++) { if (allElements[i].className =="fruit") { allElements[i].onblur=function(){ count(allElements,this); //....如果修改数据..用ajax } } } //end for } //end if } function count(els,th){ var ct=0; var this_value=th.value; if(isNaN(this_value)){ //只能数字 th.value=0; return false; } if(parseFloat(this_value)>99){ th.value=99; //小于99 } for (var i = 0; i < els.length; i++) { ct+=parseFloat((els[i].value)*(els[i].getAttribute("rel"))); } document.getElementById("b4").value=ct.toFixed(2); } </script> </head> <body background="雪花.gif"> <bgsound loop="-1" src="纯音乐-忧伤还是快乐.mp3" > <div id="a" > <br/> <h3 align="center">水果商店</h3> <br> <p align="center"> <form name="form1"> 苹果( 5元\斤 ) <input type="text" value="0" size="4" class="fruit" rel="5"> </form> <form name="form2"> 桔子(3.5元\斤) <input type="text" value="0" size="4" class="fruit" rel="3.5"> </form> <form name="form3"> 香蕉( 4元\斤 ) <input type="text" value="0" size="4" class="fruit" rel="4"> </form> <form name="form3"> 日蕉( 8元\斤 ) <input type="text" value="0" size="4" class="fruit" rel="8"> </form> <form> 总价格: <input typr="text" id="b4" disabled="disabled" value="0" size="25" /> </form> <form> <button onclick="add(5);">清零</button> </form> </p> </div> </body> </html>
------解决方案--------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BuyFruit.aspx.cs" Inherits="MessageSend.BuyFruit" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script type="