不管是HTML还是JSP,最后输出到浏览器的总是标准的HTML,所以这两个不应该有什么差别,你把浏览器中的源代码看一下,和你写的静态页面有什么区别,就能找到问题所在了

解决方案 »

  1.   

    <script language="JavaScript">
    function formatNumber(number,pattern)
            {
                    var str                        = number.toString();
                    var strInt;
                    var strFloat;
                    var formatInt;
                    var formatFloat;
                    if(/\./g.test(pattern))
                    {
                            formatInt                = pattern.split('.')[0];
                            formatFloat                = pattern.split('.')[1];
                    }
                    else
                    {
                            formatInt                = pattern;
                            formatFloat                = null;
                    }                if(/\./g.test(str))
                    {
                            if(formatFloat!=null)
                            {
                                    var tempFloat        = Math.round(parseFloat('0.'+str.split('.')[1])*Math.pow(10,formatFloat.length))/Math.pow(10,formatFloat.length);
                                    strInt                = (Math.floor(number)+Math.floor(tempFloat)).toString();                                
                                    strFloat        = /\./g.test(tempFloat.toString())?tempFloat.toString().split('.')[1]:'0';                        
                            }
                            else
                            {
                                    strInt                = Math.round(number).toString();
                                    strFloat        = '0';
                            }
                    }
                    else
                    {
                            strInt                = str;
                            strFloat        = '0';
                    }
                    if(formatInt!=null)
                    {
                            var outputInt        = '';
                            var zero                = formatInt.match(/0*$/)[0].length;
                            var comma                = null;
                            if(/,/g.test(formatInt))
                            {
                                    comma                = formatInt.match(/,[^,]*/)[0].length-1;
                            }
                            var newReg                = new RegExp('(\\d{'+comma+'})','g');                        if(strInt.length<zero)
                            {
                                    outputInt                = new Array(zero+1).join('0')+strInt;
                                    outputInt                = outputInt.substr(outputInt.length-zero,zero)
                            }
                            else
                            {
                                    outputInt                = strInt;
                            }                        var 
                            outputInt                        = outputInt.substr(0,outputInt.length%comma)+outputInt.substring(outputInt.length%comma).replace(newReg,(comma!=null?',':'')+'$1')
                            outputInt                        = outputInt.replace(/^,/,'');                        strInt        = outputInt;
                    }                if(formatFloat!=null)
                    {
                            var outputFloat        = '';
                            var zero                = formatFloat.match(/^0*/)[0].length;                        if(strFloat.length<zero)
                            {
                                    outputFloat                = strFloat+new Array(zero+1).join('0');
                                    //outputFloat                = outputFloat.substring(0,formatFloat.length);
                                    var outputFloat1        = outputFloat.substring(0,zero);
                                    var outputFloat2        = outputFloat.substring(zero,formatFloat.length);
                                    outputFloat                = outputFloat1+outputFloat2.replace(/0*$/,'');
                            }
                            else
                            {
                                    outputFloat                = strFloat.substring(0,formatFloat.length);
                            }                        strFloat        = outputFloat;
                    }
                    else
                    {
                            if(pattern!='' || (pattern=='' && strFloat=='0'))
                            {
                                    strFloat        = '';
                            }
                    }                return strInt+(strFloat==''?'':'.'+strFloat);
            }
    function FormatValue(form1,obj,pattern)

            var obj = eval('document.'+form1+'.'+obj); 
            if (obj.value!=null)
            {
                    obj.value = formatNumber(obj.value,pattern);
            } 
    }function count1() 
    {
            FormatValue('form1','ItemPrice','#.00');
            var sl = document.form1.Timess.value;
            var dj = document.form1.ItemPrice.value;
            if ((sl!="")&&(dj!=""))
            {
                    document.form1.NumB.value = sl*dj;
            }
            else
            {
                    document.form1.NumB.value = "0.00";
            }
            FormatValue('form1','NumB','#.00');
    }
    </script>以下是jsp代码,为了空间,把其他的(Form)都省略了
    <table width="100%" border="1" cellpadding="0" cellspacing="0" id=t bordercolorlight="#808080" bordercolordark="#FFFFFF" class="black"> 
      <tr align="center" bgcolor="#D4D0C8" class="black" >
        <td width="8%" height="20">序号</td>
        <td width="13%">项目名称</td>
        <td width="38%">项目内容</td>
        <td width="12%">单价</td>
        <td width="9%">数量</td>
        <td width="10%">小计</td>
        <td width="10%">删除</td>
      </tr>
    <%
    if (flag != null && flag.equals("1"))
    {
    List  PriceList =QuotationMng.getresLinePrice(request.getParameter("line"));
    priceListLength = PriceList.size();
    ResLinePrice Price;
    for(int i=0;i<5;i++)
    {
        if(i<PriceList.size())
    {
    Price = (ResLinePrice)PriceList.get(i);
    }
    else
    {
    Price = new ResLinePrice();
    }

    %>
      <tr bgcolor="#FFFFFF"> 
        <td align="center"> <strong><%=(i+1)%>&nbsp;</strong></td>
        <td align="center"><input name="ItemName<%=(i+1)%>" type="text" id="ItemName1<%=(i+1)%>" value="<%=((Price.getItemName()==null)?"":Price.getItemName())%>"></td>
        <td align="center"> <input name="ItemContent<%=(i+1)%>" type="text" id="ItemContent1<%=(i+1)%>" value="<%=((Price.getItemContent()==null)?"":Price.getItemContent())%>" style="width:95%"> </td>
        <td align="center"><input name="ItemPrice" type="text"  onKeyUp="count1();" value="<%=((Price.getItemPrice()==null)?"":Price.getItemPrice())%>" ></td>
        <td align="center"><input name="Timess" type="text"  size="10" value="" onKeyUp="value=value.replace(/\D+/g,'');count1();"></td>
        <td align="center"><input name="NumB" type="text"  readonly value="" size="6" ></td>
        <td align="center"><input name="c"  value="del" alt="删除此行数据"  type="checkbox" onClick="del();"></td>
      </tr>
    <%
    }
    }
    %>
      <tr align="right" bgcolor="#FFFFFF"> 
        <td colspan="7">合计: </td>
      </tr>
    </table>