| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 797 人关注过本帖
标题:如何在网页中限制输入字符(求帮助)
只看楼主 加入收藏
yan3844
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-7-6
结帖率:0
收藏
已结贴  问题点数:20 回复次数:8 
如何在网页中限制输入字符(求帮助)
代码:var dj=0;
var zje=0;
var bank="";
function selectA()
{
 var xh = new ActiveXObject("Msxml2.XMLHTTP");
 xh.onreadystatechange = function(){
   if(4 == xh.readyState){
    document.getElementById("selectA").innerHTML = xh.responseText;
   }
  }
 
 xh.open("GET", "class/Cselectfunction.asp?type=type", true);
 xh.send();
}
function OnSelectValue()
{
var xh = new ActiveXObject("Msxml2.XMLHTTP");
 xh.onreadystatechange = function(){
   if(4 == xh.readyState){
    document.getElementById("selectB").innerHTML = xh.responseText;
   }
  }
 
 var id=document.getElementById("type").value;
  var url="class/Cselectfunction.asp?type=cardname&id="+id;
 xh.open("GET",url , true);
 xh.send();

}
function OnSelectValueB()
{
var xh = new ActiveXObject("Msxml2.XMLHTTP");
 xh.onreadystatechange = function(){
   if(4 == xh.readyState){
    document.getElementById("money").innerHTML = xh.responseText;
    dj=xh.responseText;
   }
  }
 
 var id=document.getElementById("Cname").value;
  var url="class/Cselectfunction.asp?type=money&id="+id;
 xh.open("GET",url , true);
 xh.send();

}
function CheckMoney()
{
zje=dj*document.getElementById("shs").value;
document.getElementById("GoodPrice").innerHTML=zje;
}
function button1click()
{
var subject;//=document.getElementById("Cname").text;//商品名
subject=document.getElementById("Cname").options[document.getElementById("Cname").selectedIndex].text;
var body='在线自动发卡系统';//商品描述
var total_fee=zje; //总金额
var qq=document.getElementById("QQ").value;//QQ或email
var pay_mode;
var defaultbank;
var num=document.getElementById("shs").value;//订购数量   
var subjectid=document.getElementById("Cname").options[document.getElementById("Cname").selectedIndex].value;
Foo();
if(bank=="ZFB"||bank==""){
pay_mode='directPay';//支付方式
defaultbank="";
}else
{
pay_mode='bankPay';//支付方式
defaultbank=bank;//默认银行
}
location.href="alipayto.asp?subject="+subject+"&body="+body+"&total_fee="+total_fee+"&pay_mode="+pay_mode+"&defaultbank="+defaultbank+"&QQ="+qq+"&num="+num+"&subjectid="+subjectid;
}
function Foo()
{
    var selectedIndex = -1;
    var form1 = document.getElementById("form1");
    var i = 0;
    for (i=0; i<form1.default_bank_S.length; i++)
    {
        if(form1.default_bank_S[i].checked)
        {
            selectedIndex = i;
            bank= form1.default_bank_S[i].value;
            break;
        }
    }
   
    if (selectedIndex < 0)
    {
        bank="";
    }
}


怎么修改设置禁止输入字符,如:!@#$%^这些字符
搜索更多相关主题的帖子: 如何 网页 function class 
2011-07-06 12:43
cRazy谢不清
Rank: 2
等 级:论坛游民
帖 子:25
专家分:86
注 册:2011-6-27
收藏
得分:5 
什么意思呢?具体一点。你是要在别人在文本框输入数量时 限制输入字符吗?
2011-07-06 12:53
yan3844
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-7-6
收藏
得分:0 
是的
在输入宽里面限制不能输入字符
2011-07-06 12:56
yan3844
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-7-6
收藏
得分:0 
<title>自动发卡平台</title>
<style type="text/css">
* {
    margin: 0;
    padding: 0px;
    font-family: Arial, Helvetica, sans-serif;
}
body {
    background: #4D9AA7 url(images/bg2.gif) top repeat-x;
    font-size: 14px;
}
#main {
    width: 950px;
    margin: auto;
    background: #fff;
    padding: 10px;
}
.top_space {
    margin-top: 10px;
}
.font_142 {
    color: #333;
    font-size: 14px;
}
#GoodPrice {
    font-size: 16px;
    color: red;
    font-weight: bold;
}
#shs {
    padding: 3px;
    border: 1px solid #0063DC;
    background: #EDF7FE;
}
a:hover {
    text-decoration: none;
}
.style1 {
    text-align: left;
}
.STYLE2 {
    font-size: 12px;
    color: #FF0000;
}
</style>
<script language="javascript">
var dj=0;
var zje=0;
var bank="";
function selectA()
{
 var xh = new ActiveXObject("Msxml2.XMLHTTP");
 xh.onreadystatechange = function(){
   if(4 == xh.readyState){
    document.getElementById("selectA").innerHTML = xh.responseText;
   }
  }
 
 xh.open("GET", "class/Cselectfunction.asp?type=type", true);
 xh.send();
}
function OnSelectValue()
{
var xh = new ActiveXObject("Msxml2.XMLHTTP");
 xh.onreadystatechange = function(){
   if(4 == xh.readyState){
    document.getElementById("selectB").innerHTML = xh.responseText;
   }
  }
 
 var id=document.getElementById("type").value;
  var url="class/Cselectfunction.asp?type=cardname&id="+id;
 xh.open("GET",url , true);
 xh.send();

}
function OnSelectValueB()
{
var xh = new ActiveXObject("Msxml2.XMLHTTP");
 xh.onreadystatechange = function(){
   if(4 == xh.readyState){
    document.getElementById("money").innerHTML = xh.responseText;
    dj=xh.responseText;
   }
  }
 
 var id=document.getElementById("Cname").value;
  var url="class/Cselectfunction.asp?type=money&id="+id;
 xh.open("GET",url , true);
 xh.send();

}
function CheckMoney()
{
zje=dj*document.getElementById("shs").value;
document.getElementById("GoodPrice").innerHTML=zje;
}
function button1click()
{
var subject;//=document.getElementById("Cname").text;//商品名
subject=document.getElementById("Cname").options[document.getElementById("Cname").selectedIndex].text;
var body='在线自动发卡系统';//商品描述
var total_fee=zje; //总金额
var qq=document.getElementById("QQ").value;//QQ或email
var pay_mode;
var defaultbank;
var num=document.getElementById("shs").value;//订购数量   
var subjectid=document.getElementById("Cname").options[document.getElementById("Cname").selectedIndex].value;
Foo();
if(bank=="ZFB"||bank==""){
pay_mode='directPay';//支付方式
defaultbank="";
}else
{
pay_mode='bankPay';//支付方式
defaultbank=bank;//默认银行
}
location.href="alipayto.asp?subject="+subject+"&body="+body+"&total_fee="+total_fee+"&pay_mode="+pay_mode+"&defaultbank="+defaultbank+"&QQ="+qq+"&num="+num+"&subjectid="+subjectid;
}
function Foo()
{
    var selectedIndex = -1;
    var form1 = document.getElementById("form1");
    var i = 0;
    for (i=0; i<form1.default_bank_S.length; i++)
    {
        if(form1.default_bank_S[i].checked)
        {
            selectedIndex = i;
            bank= form1.default_bank_S[i].value;
            break;
        }
    }
   
    if (selectedIndex < 0)
    {
        bank="";
    }
}



</script>
</head>

<body onload="selectA();">
<div id="main">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="images/fa.gif" width="162" height="34" align="absmiddle" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" align="center"><img src="images/line.gif" width="100%" height="10" /></td>
  </tr>
</table>
  <table border="0" cellpadding="0" cellspacing="0" class="top_space" width="100%">
        <tr>
            <td width="68%">
            <form name="form1" id="form1">
                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <td height="36" style="background: url(images/bg8.gif);">
                        <table align="center" border="0" cellpadding="0" cellspacing="0" width="95%">
                            <tr>
                                <td width="4%">
                                <img height="22" src="images/1.gif" width="22" /></td>
                                <td style="font-weight: bold; color: #000;" width="96%">
                                第一步:选择商品</td>
                            </tr>
                        </table>
                        </td>
                    </tr>
                    <tr>
                        <td><br />
                        <table align="center" border="0" cellpadding="5" cellspacing="0" width="80%">
                            <tr>
                                <td height="30" style="font-weight: bold; color: #666;">
                                商品分类:</td>
                                <td>
                                <div id="selectA">
                                </div>
                                </td>
                                <td><span id="Bclass"><span class="font_142">请选择商品分类</span></span></td>
                            </tr>
                            <tr>
                                <td height="30" style="font-weight: bold; color: #666;">
                                商品名称:</td>
                                <td class="font_142">
                                <div id="selectB">
                                </div>
                                </td>
                                <td class="font_142">请选择商品名称</td>
                            </tr>
                            <tr>
                                <td height="30" style="font-weight: bold; color: #666;">
                                商品单价:</td>
                                <td class="font_142" style="font-size: 16px; font-weight: bold; color: #F00;">
                                <div id="money">
                                </div>
                                </td>
                                <td class="font_142">元</td>
                            </tr>
                            <tr>
                                <td height="30" style="font-weight: bold; color: #666;">
                                购买数量:</td>
                                <td class="font_142">
                                <input id="shs" name="shs" onkeyup="CheckMoney();" size="10" type="text" value="0" /></td>
                                <td class="font_142" style="font-size: 18px; font-weight: bold; color: green;">
                                <span id="kucun"></span></td>
                            </tr>
                        </table>
                        </td>
                    </tr>
                </table>
                <table align="center" bgcolor="#FF9966" border="0" cellpadding="0" cellspacing="1" class="top_space" width="100%">
                    <tr>
                        <td bgcolor="#FFFFCC" height="30" style="text-align: center; font-size: 16px; font-weight: bold;">
                        应付金额:<span id="GoodPrice">0</span> 元 (人民币)</td>
                    </tr>
                </table>
                <br />
                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <td height="36" style="background: url(images/bg8.gif);">
                        <table align="center" border="0" cellpadding="0" cellspacing="0" width="95%">
                            <tr>
                                <td width="4%">
                                <img height="22" src="images/2.gif" width="22" /></td>
                                <td style="font-weight: bold; color: #000;" width="96%">
                                第二步:选择支付方式</td>
                            </tr>
                        </table>
                        </td>
                    </tr>
                    <tr>
                        <td>
                        <table align="center" border="0" cellpadding="0" cellspacing="0" width="90%">
                            <tr>
                                <td>
                                <div id="bank">
                                    <table align="center" border="0" cellpadding="0" cellspacing="0" width="90%">
                                        <tr>
                                            <td>
                                            <table align="center" border="0" cellpadding="0" cellspacing="0" class="top_space" style="font-size: 14px;" width="98%">
                                                <tr>
                                                    <td width="86%">
                                                    <input id="PayType2" name="PayType2" type="hidden" value="48" />
                                                    </td>
                                                </tr>
                                            </table>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                </td>
                            </tr>
                            <tr>
                                <td height="10">
                                <table align="center" border="0" cellpadding="2" cellspacing="0" width="100%">
                                    <tr>
                                        <td class="td1" height="25">
                                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                            <tr>
                                                <td align="center" colspan="4" height="35" width="400">
                                                <table align="left" border="0" cellspacing="8" style="width: 400">
                                                    <tr>
                                                        <td class="style1" nowrap="" style="width: 30%">
                                                        <input name="default_bank_S" type="radio" value="ICBCB2C">
                                                        <img alt="中国工商银行" border="1" height="20" src="https://img. width="107"></td>
                                                        <td class="style1" width="33%">
                                                        <input name="default_bank_S" type="radio" value="ABC">
                                                        <img alt="中国农业银行" border="0" height="20" src="https://img. width="107"></td>
                                                        <td class="style1" nowrap="">
                                                        <input name="default_bank_S" type="radio" value="CCB">
                                                        <img alt="中国建设银行" border="0" height="20" src="https://img. width="107"></td>
                                                    </tr>
                                                    <tr>
                                                        <td class="style1" style="width: 30%">
                                                        <input name="default_bank_S" type="radio" value="CMB">
                                                        <img alt="招商银行" border="0" src="https://img.
                                                        <td class="style1" nowrap="">
                                                        <input name="default_bank_S" type="radio" value="GDB">
                                                        <img alt="广东发展银行" border="0" height="20" src="https://img. width="107">
                                                        </td>
                                                        <td class="style1">
                                                        <input name="default_bank_S" type="radio" value="CIB">
                                                        <img alt="兴业银行" border="0" height="20" src="https://img.
                                                    </tr>
                                                    <tr>
                                                        <td class="style1" nowrap="" style="width: 30%">
                                                        <input name="default_bank_S" type="radio" value="SDB">
                                                        <img alt="深圳发展银行" border="0" height="20" src="https://img. width="107"></td>
                                                        <td class="style1">
                                                        <input name="default_bank_S" type="radio" value="CMBC">
                                                        <img alt="中国民生银行" border="0" height="20" src="https://img.
                                                        <td class="style1" nowrap="">
                                                        <input name="default_bank_S" type="radio" value="SPDB">
                                                        <img alt="上海浦东发展银行" border="0" src="https://img.
                                                    </tr>
                                                    <tr>
                                                        <td class="style1" nowrap="" style="width: 30%">
                                                        <input name="default_bank_S" type="radio" value="CITIC">
                                                        <img alt="中信银行" border="0" height="20" src="https://img.
                                                        <td class="style1">
                                                        <input name="default_bank_S" type="radio" value="COMM">
                                                        <img alt="交通银行" border="0" height="20" src="https://img.
                                                        <td class="style1" nowrap="">
                                                        <input name="default_bank_S" type="radio" value="CEBBANK">
                                                        <img alt="中国光大银行" border="0" height="20" src="https://img.
                                                    </tr>
                                                    <tr>
                                                        <td class="style1" nowrap="" style="width: 30%">
                                                        <input name="default_bank_S" type="radio" value="BOCB2C">
                                                        <img alt="中国银行" border="0" height="20" src="https://img.
                                                        <td class="style1" nowrap="">
                                                        <input name="default_bank_S" type="radio" value="HZCBB2C">
                                                        <img alt="杭州银行" border="0" height="20" src="https://img.
                                                        <td class="style1" nowrap="">
                                                        <input name="default_bank_S" type="radio" value="SHBANK">
                                                        <img alt="上海银行" border="0" height="20" src="https://img.
                                                    </tr>
                                                    <tr>
                                                        <td class="style1" nowrap="" style="width: 30%">
                                                        <input name="default_bank_S" type="radio" value="NBBANK">
                                                        <img alt="宁波银行" border="0" height="20" src="https://img. width="107"></td>
                                                        <td class="style1" nowrap="">
                                                        <input name="default_bank_S" type="radio" value="SPABANK">
                                                        <img alt="平安银行" border="0" height="20" src="https://img. width="107"></td>
                                                    </tr>
                                                </table>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="style1" height="35" style="width: 10px">
                                                <input checked="checked" class="bigradio" name="default_bank_S" type="radio" value="ZFB" />
                                                </td>
                                                <td>
                                                <img align="absmiddle" alt="支付宝" border="0" height="33" src="images/alipay.gif" width="154" />
                                                </td>
                                                <td align="center">&nbsp;</td>
                                                <td>&nbsp;</td>
                                            </tr>
                                        </table>
                                        </td>
                                    </tr>
                                </table>
                                </td>
                            </tr>
                        </table>
                        </td>
                    </tr>
                </table>
                <table border="0" cellpadding="0" cellspacing="0" class="top_space" width="100%">
                    <tr>
                        <td align="center">
                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
                            <tr>
                                <td height="36" style="background: url(images/bg8.gif);">
                                <table align="center" border="0" cellpadding="0" cellspacing="0" width="95%">
                                    <tr>
                                        <td width="4%">
                                        <img height="22" src="images/3.gif" width="22" /></td>
                                        <td class="style1" style="font-weight: bold; color: #000;" width="96%">
                                        第三步:填写联系信息</td>
                                    </tr>
                                </table>
                                </td>
                            </tr>
                            <tr>
                                <td><br />
                                <table align="center" border="0" cellpadding="0" cellspacing="0" width="98%">
                                    <tr>
                                        <td>
                                        <table border="0" cellpadding="0" cellspacing="0" class="top_space" width="100%">
                                            <tr>
                                                <td>
                                                <table border="0" cellpadding="10" cellspacing="0" width="100%">
                                                    <tr>
                                                        <td align="middle" height="30" style="width: 141px">&nbsp;</td>
                                                        <td class="style1"><span style="width: 141px">联系方式</span>QQ或E_mail:
                                                          <input id="QQ" name="QQ"  type="text" value="" />
                                                      <span class="STYLE2">没有QQ可以填写手机。</span></td>
                                                    </tr>
                                                </table>
                                                </td>
                                            </tr>
                                        </table>
                                        </td>
                                    </tr>
                                </table>
                                </td>
                            </tr>
                        </table>
                        </td>
                    </tr>
                    <tr>
                        <td align="center"><label>
<input name="Button1" type="button" value="下一步,立即购买" onclick="button1click();" />
                        </label></td>
                    </tr>
                </table>
            </form>
            </td>
        </tr>
  </table>
    <table align="center" border="0" cellpadding="0" cellspacing="0" style="margin-top: 15px;" width="100%">
        <tr>
            <td align="center" style="height: 20px; font-size: 12px; text-align: center; color: #999;">
            <img height="10" src="images/line.gif" width="100%" /></td>
        </tr>
        <tr>
            <td style="height: 50px; font-size: 12px; text-align: center; color: #999;">
            &copy; 2009-2011 自动发卡平台</td>
        </tr>
    </table>
2011-07-06 13:00
cRazy谢不清
Rank: 2
等 级:论坛游民
帖 子:25
专家分:86
注 册:2011-6-27
收藏
得分:0 
<input type="text" onchange="checkNum(this)" />
function Num(obj)
    {
  _thelast = obj.value.charCodeAt(obj.value.length-1); //获取刚输入的那个字符
    if(!IsNaN(_thelast)) //判断输入的字符是否为数值
       {
            obj.value.length =obj.value.length-1; //如果不是字符,删除最后一个字符。
        }
   }
2011-07-06 15:57
BeBass
Rank: 2
来 自:四川达州渠县/深圳宝安福永
等 级:论坛游民
帖 子:11
专家分:71
注 册:2010-8-24
收藏
得分:5 
学习ING

小店探底价,http://aiml100.
2011-07-06 17:05
QQ273080973
Rank: 2
等 级:论坛游民
帖 子:14
专家分:39
注 册:2011-7-7
收藏
得分:5 
禁止输入 $ % & *,输入这些字符将被自动清除:<input onkeyup="this.value=this.value.replace(/[\$\%\&\*]+/,'');" value="" size="20">

看看这样行不行
2011-07-08 12:11
hry311
Rank: 1
等 级:新手上路
帖 子:5
专家分:5
注 册:2007-6-15
收藏
得分:5 
回复 5楼 cRazy谢不清
正解啊!!
2011-07-09 20:00
hry311
Rank: 1
等 级:新手上路
帖 子:5
专家分:5
注 册:2007-6-15
收藏
得分:0 
以下是引用hry311在2011-7-9 20:00:58的发言:

正解啊!!
2011-07-09 20:02
快速回复:如何在网页中限制输入字符(求帮助)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035661 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved