首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET Framework >

请问一个输入数字后判断的有关问题

2012-02-19 
请教一个输入数字后判断的问题C# codehtml xmlnshttp://www.w3.org/1999/xhtmlhead runatserver

请教一个输入数字后判断的问题

C# code
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title>无标题页</title>     <script src="../../js/jquery.js" type="text/javascript"></script>        <script type="text/javascript">       $(document).ready(function(){       var txtOne=document.getElementById("txtRedOne");       if(txtOne<10)       {        txtOne="0"+txtOne;       }       }        </script></head><body>    <form id="form1" runat="server">    <div>    <asp:TextBox ID="txtRedOne" runat="server" Text=""   onkeyup="if(isNaN(value))execCommand('undo')" MaxLength="12"                     BorderStyle="None"></asp:TextBox>    </div>    </form></body></html>问题:当我输入数字小于10的时候,前面加0,例如,我输入数字5,当鼠标移出,就会变为05!


[解决办法]
C# code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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 runat="server">    <title></title></head><body>    <form id="form1" runat="server">    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>    <div>    </div>    </form></body><script>    document.getElementById("TextBox1").onblur = function () {        if (this.value.length < 2)            this.value = "0" + this.value;    }</script></html>
[解决办法]
HTML code
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title>无标题页</title><script src="../../js/jquery.js" type="text/javascript"></script>    <script type="text/javascript">        $(document).ready(function() {            $('#txtRedOne').blur(function() {                var val = parseInt($(this).val(),10);                if (val < 10)                    $(this).val('0' + val);                else                    $(this).val(val);            });        });    </script></head><body>    <form id="form1" runat="server">    <div>        <asp:TextBox ID="txtRedOne" runat="server" Text="" onkeyup="if(isNaN(value))execCommand('undo')"            MaxLength="12" BorderStyle="None"></asp:TextBox>    </div>    </form></body> 

热点排行