如何修改此脚本以允许负数? [英] How to modify this script to allow negative numbers??

查看:114
本文介绍了如何修改此脚本以允许负数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Rob B在另一个帖子中发布了这个精彩的代码,

http://groups.google.com/group/comp....ad9d5e61be85f0


我无法弄清楚如何使用Google

群体回复帖子本身,所以请原谅我切割和粘贴(我给他发了电子邮件

但他可能没有时间检查他的电子邮件),我希望有人

可以告诉我如何更改此脚本以允许否定

数字。


我的问题是:


如何修改它以允许减号允许负数?


我想在购买申请表中使用它,有时需要

负数。


理想情况下我想允许输入负数,然后当它去的时候

到打印我想重新格式化(使用JS或CSS)所以它

有()显示它是

a负数/信用类型的应付账款相应地行动




谢谢你,汤姆


变色龙生活! :-)

欢迎您,Rogue。


<?xml version =" 1.0" encoding =" iso-8859-1"?>

<!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。组织/ 1999 / XHTML" XML:朗= QUOT;恩" lang =" en">

< head>

< title>无标题< / title>

< script type = " text / javascript">

//<![CDATA [

cF.RE1 = / ^ \ d * \。? \ * * $ ;;

cF.RE2 = /\.\d{3,}$/;

cF.RE3 = / \。( ?= [^。] * \。)/ g;

cF.RE4 = /[^\d.]/g;

cF.RE5 = / \。(?= [^。] * \。)/ g;

cF.RE6 = /^(\d*\.\d{2})。+ $ /;

cF.RE7 = /(\.\\\{0,1})$/;

cF.RE8 = / ^([^。] +)$ /;


String.prototype.reverse = function()

{

返回this.split('' '')。reverse()。join('''');


}


函数cF(fld,onblur)

{

var v = fld.value;

if(!cF.RE1.test(v)|| cF.RE2.test(v ))

{

var ltdot =(fld.dotpos == v.indexOf(''。'')?

v.lastIndexOf (''。'')< fld.dotpos:

v.indexOf (''。'')< fld.dotpos);

if(ltdot)

v = v.reverse();

v = v.replace(cF.RE3,'''');

if(ltdot)

v = v.reverse();

v = v.replace(cF.RE4,'''')。

替换(cF.RE5,'''')。

替换(cF.RE6,'' $ 1'');

fld.value = v;

}

fld.dotpos = v.indexOf(''。'') ;

if(onblur)

fld.value = v.replace(cF.RE7,''$ 10'')。

replace( cF.RE7,''$ 10'')。

替换(cF.RE8,''$ 1.00'');


}


//]]>

< / script>

< / head>

< body style =" font:100%arial; margin:300px;"

onload =" f = document.forms [0]; f.reset(); f.foo.focus() ">

< form onreset =" foo.focus()">

$< input type =" text"名称= QUOT; FOO"值= QUOT;"大小= QUOT; 10" maxlength =" 8"

style =" font:75%arial; text-align:center; border:1px black solid;"

onkeyup =" return cF(this,false)"

onblur =" return cF(this,true)" />

< input type =" reset"值= QUOT;清零" style =" font:75%arial; border:1px

black

solid;" />

< / form>

< / body>

< / html>


***通过开发人员指南 http://www.developersdex.com 发送* **

不要只是参加USENET ......获得奖励!

Hello Rob B posted this wonderful code in another thread,

http://groups.google.com/group/comp....ad9d5e61be85f0

I could not figure out how to reply to the thread per se using Google
Groups and so please forgive me for cutting and pasting (I emailed him
but he may not have time to check his email), and I am hoping someone
might be able to tell me how I can change this script to allow negative
numbers.

My question is:

How can I modify it to allow a minus sign to allow negative numbers??

I want to use it in a purchase requisition form where sometimes
negative numbers are necessary.

Ideally I want to allow a negative number typed in, then when it goes
to be printed I would want to reformat it (either with JS or CSS) so it
has ( ) to show it is
a negative/credit type of number for Accounts Payable to act
accordingly.

Thank you, Tom

The Chameleon Lives! :-)
Your welcome, Rogue.

<?xml version="1.0" encoding="iso-8859-1"?>
<!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" xml:lang="en" lang="en">
<head>
<title>untitled</title>
<script type="text/javascript">
//<![CDATA[

cF.RE1 = /^\d*\.?\d*$/;
cF.RE2 = /\.\d{3,}$/;
cF.RE3 = /\.(?=[^.]*\.)/g;
cF.RE4 = /[^\d.]/g;
cF.RE5 = /\.(?=[^.]*\.)/g;
cF.RE6 = /^(\d*\.\d{2}).+$/;
cF.RE7 = /(\.\d{0,1})$/;
cF.RE8 = /^([^.]+)$/;

String.prototype.reverse = function()
{
return this.split('''').reverse().join('''');

}

function cF(fld, onblur)
{
var v = fld.value;
if (!cF.RE1.test(v) || cF.RE2.test(v))
{
var ltdot = (fld.dotpos == v.indexOf(''.'') ?
v.lastIndexOf(''.'') < fld.dotpos :
v.indexOf(''.'') < fld.dotpos);
if (ltdot)
v = v.reverse();
v = v.replace(cF.RE3,'''');
if (ltdot)
v = v.reverse();
v = v.replace(cF.RE4,'''').
replace(cF.RE5,'''').
replace(cF.RE6,''$1'');
fld.value = v;
}
fld.dotpos = v.indexOf(''.'');
if (onblur)
fld.value = v.replace(cF.RE7, ''$10'').
replace(cF.RE7, ''$10'').
replace(cF.RE8, ''$1.00'');

}

//]]>
</script>
</head>
<body style="font:100% arial;margin:300px;"
onload="f=document.forms[0];f.reset();f.foo.focus()">
<form onreset="foo.focus()">
$ <input type="text" name="foo" value="" size="10" maxlength="8"
style="font:75% arial;text-align:center;border:1px black solid;"
onkeyup="return cF(this,false)"
onblur="return cF(this,true)" />
<input type="reset" value="clear" style="font:75% arial;border:1px
black
solid;" />
</form>
</body>
</html>

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!

推荐答案

/;

cF.RE2 = /\.\d{3,}
/;
cF.RE2 = /\.\d{3,}


/;

cF.RE3 = /\.(?=[^.]*\。)/ g;

cF.RE4 = /[^\d.]/g;

cF.RE5 = /\.(?=[^.]*\。)/ g;

cF.RE6 = / ^(\d * \\\ { 2})。+
/;
cF.RE3 = /\.(?=[^.]*\.)/g;
cF.RE4 = /[^\d.]/g;
cF.RE5 = /\.(?=[^.]*\.)/g;
cF.RE6 = /^(\d*\.\d{2}).+


/;

cF.RE7 = /(\.\d{0,1})
/;
cF.RE7 = /(\.\d{0,1})


这篇关于如何修改此脚本以允许负数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆