请问(/\D/gi,"")'是什么意思?
请问(/\D/gi,"")'是什么意思?
正则表达式中的替换
\D 代表非数字 gi 表示 全局的和忽略大小写
""代表将非数字替换成""(即删除非数字字符)
[此贴子已经被作者于2006-6-25 15:44:41编辑过]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>仅供幼稚园使用</title>
<script language="javascript">
function shi(form1)
{
var sum1=parseInt(form1.a.value);
var sum2=parseInt(form1.b.value);
if (form1.sdh.value=="+")
{
form1.c.value=sum1+sum2;
}
if (form1.sdh.value=="-")
{
form1.c.value=sum1-sum2;
}
if (form1.sdh.value=="*")
{
form1.c.value=sum1*sum2;
}
if (form1.sdh.value=="/")
{
form1.c.value=sum1/sum2;
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<input name="a" type="text" id="a" size="8" onkeyup='this.value=this.value.replace(/\D/gi,"")'>
<select name="sdh" id="sdh">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input name="b" type="text" id="b" size="8" onkeyup='this.value=this.value.replace(/\D/gi,"")'>
<input type="button" name="Submit2" value="=" onclick="return shi(this.form)">
<input name="c" type="text" id="c" size="8">
</form>
</body>
</html>