如何强制输入数字???在线等。。。 onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function checkIsFloat(){ var nc=event.keyCode; var tf=document.getElementById('textfield'); var s=tf.value; if((nc>=48) && (nc<=57) ){ var ndot=s.indexOf('.'); if(ndot!=-1){ if((s.length-ndot>6) ||(ndot>10)){ event.keyCode=0; return; }else if(ndot>10){ tf.value=''; } }else{ if(s.length>10){ tf.value=''; } } }else if(nc==46){ for(var i=0;i<s.length;i++){ if(s.charAt(i)=='.'){ event.keyCode=0; return; } } }else{ event.keyCode=0;return; } }<input type="text" name="textfield" onKeyPress="checkIsFloat();"> to numen27(影子):好像不行,我的小数点也输不上了 改一下,这样就完美了 function checkIsFloat(){ var nc=event.keyCode; var tf=document.getElementById('textfield'); var s=tf.value; if((nc>=48) && (nc<=57) ){ var ndot=s.indexOf('.'); if(ndot!=-1){ if(s.length-ndot>6 ){ event.keyCode=0; return; } }else{ if(s.length>=10){ event.keyCode=0;tf.value=''; return; } } }else if(nc==46){ for(var i=0;i<s.length;i++){ if(s.charAt(i)=='.'){ event.keyCode=0; return; } } }else{ event.keyCode=0;return; } }<input type="text" name="textfield" onKeyPress="checkIsFloat();"> function isSpecifyDecimal(str,intLen,speciLen) { if (str.length != 0) { // is number if (str.search(/[^0-9.]/g) != -1){ return false;//不是数字 } var dateArray=str.split("."); if ((dateArray.length > 2)) { return false;//有两个'.' } else if(dateArray.length == 1){//没有小数点 if(str.length > intLen)//intLen整数位数 return false;//超过整数位数 } else{//有小数点 if (dateArray[0].length > intLen) { return false; } if (dateArray[1].length > speciLen) { return false; } } } return true; } <script>function aa(){var a,b,c,da=document.form1.text1.valueb=a.lengthif(b<=17){ for(c=0,c<=b,c++){ d=c+1 if(a.substr(c,d)%2==0){ if(a.substr(c,d)%2==1){ if(String(d).lenght<=10){ document.alert("符合标准") } else{ document.alert("不符合标准") } } else{ if(a.substr(c,d)=="."){ if(a.substr(c,d)%2==0){ if(a.substr(c,d)%2==1){ if(String(d).lenght<=7){ document.alert("符合标准") } } } } } else{ document.alert("不符合标准") } } }</script> 或者<script> function bb(){ var a,b,c,d a=document.form1.text1.vlaue c=String(a) b=a.length if(a%2==0){ if(a%2==1){ } } else{ if(a=="."){ d++ if(c.length<=10){ } else{ document.alert("不符合标准") } } else{ document.alert("不符合标准") } c=String(a)+String(a) if(c.length<=17){ document.alert("不符合标准") else{ c=document.form1.text1.vlaue } if(d>1){ document.alert("不符合标准") } }abc=setTimeout("bb()",10)}<body><form name="from1"><input type="text" name="text1" onfocus="bb()"></form></body> 上面的有错误 function bb(){ var a,b,c,d d=0 a=document.form1.text1.vlaue c=String(a) b=a.length if(a%2==0){ if(a%2==1){ } } else{ if(a=="."){ d++ if(c.length<=10){ } else{ document.alert("不符合标准") } } else{ document.alert("不符合标准") } c=String(a)+String(a) if(c.length<=17){ document.alert("不符合标准") else{ c=document.form1.text1.vlaue } if(d>1){ document.alert("不符合标准") } }abc=setTimeout("bb()",10)}<body><form name="from1"><input type="text" name="text1" onfocus="bb()"></form></body> onKeyDown如果没理解我写完整代码好了 为什么是这样? javascript能否改变iframe的frameborder属性的值 谢谢高手了!请问,如何在javasciprt中调用vb开发的组件返回的数组 关于日历的问题,想了好久,不知怎样解决 求助一个简单问题 如何得到一个form中的所有文本域! 谁能详细说明一下execcommend的详细用法 怎样固定菜单? 求助一段js 谁能给我一个js过滤器?? 高手请指点。关于FRAME问题 当代码里有多个引号时怎么解决?
var nc=event.keyCode;
var tf=document.getElementById('textfield');
var s=tf.value;
if((nc>=48) && (nc<=57) ){
var ndot=s.indexOf('.');
if(ndot!=-1){
if((s.length-ndot>6) ||(ndot>10)){
event.keyCode=0; return;
}else if(ndot>10){
tf.value='';
}
}else{
if(s.length>10){
tf.value='';
}
}
}else if(nc==46){
for(var i=0;i<s.length;i++){
if(s.charAt(i)=='.'){
event.keyCode=0; return;
}
}
}else{
event.keyCode=0;return;
}
}<input type="text" name="textfield" onKeyPress="checkIsFloat();">
好像不行,我的小数点也输不上了
function checkIsFloat(){
var nc=event.keyCode;
var tf=document.getElementById('textfield');
var s=tf.value;
if((nc>=48) && (nc<=57) ){
var ndot=s.indexOf('.');
if(ndot!=-1){
if(s.length-ndot>6 ){
event.keyCode=0; return;
}
}else{
if(s.length>=10){
event.keyCode=0;tf.value=''; return;
}
}
}else if(nc==46){
for(var i=0;i<s.length;i++){
if(s.charAt(i)=='.'){
event.keyCode=0; return;
}
}
}else{
event.keyCode=0;return;
}
}
<input type="text" name="textfield" onKeyPress="checkIsFloat();">
{
if (str.length != 0)
{
// is number
if (str.search(/[^0-9.]/g) != -1){
return false;//不是数字
}
var dateArray=str.split(".");
if ((dateArray.length > 2))
{
return false;//有两个'.'
}
else if(dateArray.length == 1){//没有小数点
if(str.length > intLen)//intLen整数位数
return false;//超过整数位数
}
else{//有小数点
if (dateArray[0].length > intLen)
{
return false;
}
if (dateArray[1].length > speciLen)
{
return false;
} } }
return true; }
function aa(){
var a,b,c,d
a=document.form1.text1.value
b=a.length
if(b<=17){
for(c=0,c<=b,c++){
d=c+1
if(a.substr(c,d)%2==0){
if(a.substr(c,d)%2==1){
if(String(d).lenght<=10){
document.alert("符合标准")
}
else{
document.alert("不符合标准")
}
}
else{
if(a.substr(c,d)=="."){
if(a.substr(c,d)%2==0){
if(a.substr(c,d)%2==1){
if(String(d).lenght<=7){
document.alert("符合标准")
}
}
}
}
}
else{
document.alert("不符合标准")
}
}
}
</script>
<script>
function bb(){
var a,b,c,d
a=document.form1.text1.vlaue
c=String(a)
b=a.length
if(a%2==0){
if(a%2==1){
}
}
else{
if(a=="."){
d++
if(c.length<=10){
}
else{
document.alert("不符合标准")
}
}
else{
document.alert("不符合标准")
}
c=String(a)+String(a)
if(c.length<=17){
document.alert("不符合标准")
else{
c=document.form1.text1.vlaue
}
if(d>1){
document.alert("不符合标准")
}
}
abc=setTimeout("bb()",10)
}
<body>
<form name="from1">
<input type="text" name="text1" onfocus="bb()">
</form>
</body>
function bb(){
var a,b,c,d
d=0
a=document.form1.text1.vlaue
c=String(a)
b=a.length
if(a%2==0){
if(a%2==1){
}
}
else{
if(a=="."){
d++
if(c.length<=10){
}
else{
document.alert("不符合标准")
}
}
else{
document.alert("不符合标准")
}
c=String(a)+String(a)
if(c.length<=17){
document.alert("不符合标准")
else{
c=document.form1.text1.vlaue
}
if(d>1){
document.alert("不符合标准")
}
}
abc=setTimeout("bb()",10)
}
<body>
<form name="from1">
<input type="text" name="text1" onfocus="bb()">
</form>
</body>