javascript 函数 输入框校验 日期加减
【代码】javascript 函数 输入框校验 日期加减。
·
day10记录
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>系统函数</title>
<script>
document.write(eval("3+6")+"<br>")
document.write(isFinite(12))
document.write(isFinite("魏无羡不好看"))
document.write(isNaN(12))
document.write(isNaN("易水寒"))
document.write(isNaN("100"))
document.write(Number("888 999"))
document.write(Number("肖战"))
document.write(parseInt("23"))
document.write(parseFloat("23 22 21"))
document.write(decodeURL())
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>校验输入框类型</title>
<script>
function isRight(subChar)
{
var findChar="qwertyuiopasdfghjklzxcvbnm";
for (var i=0;i<subChar.length;i++)
{
if(findChar.indexOf(subChar.charAt(i))==-1)
{
alert("你输入的字符合法");
return;
}
}
alert("你输入的字符不合法")
}
</script>
</head>
<body>
<form action="" method="post" name="myform" id="myform">
<input type="text" name="txtString">
<input type="button" value="检查" onclick="isRight(document.myform.txtString.value)">
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>购物车简易计算器</title>
<style>
section{
width:260px;
background-color:#c9e495;
height:350px;
text-align:center;
padding-top:1px;
}
.textBaroder{
border-width:1px;
border-style:solid;
}
</style>
<script>
function compute(op)
{
var num1,num2;
num1=parseFloat(document.myform.txtNum1.value);
num2=parseFloat(document.myform.txtNum2.value);
if (op=="+")
document.myform.txtResult.value=num1+num2;
if (op=="-")
document.myform.txtResult.value=num1-num2;
if (op=="*")
document.myform.txtResult.value=num1*num2;
if (op=="/"&& num2!=0)
document.myform.txtResult.value=num1/num2;
}
</script>
</head>
<body>
<section>
<h1><img src="../护眼.jpg" width="240" height="31">欢迎光临!</h1>
<form action="" method="post" name="myform" id="myform">
<h3><img src="../护眼.jpg" width="54" height="54">购物简易计算器</h3>
<p>第一个数<input type="text" name="txtNum1" class="textBaroder" id="txtNum1" size="25"></p>
<p>第二个数<input type="text" name="txtNum2" class="textBaroder" id="txtNum2" size="25"></p>
<p>
<input name="addButton2" type="button" id="addButton2" value=" + " onclick="compute('+')">
<input name="subButton2" type="button" id="subButton2" value=" - " onclick="compute('-')">
<input name="multButton2" type="button" id="multButton2" value=" * " onclick="compute('*')">
<input name="divButton2" type="button" id="divButton2" value=" / " onclick="compite('/')"></p>
<P>计算结果<input name="txtResult" type="text" class="textBaroder" id="txtResult" size="25">
</P>
</form>
</section>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>校验输入框类型</title>
<script>
function isRight(subChar)
{
var findChar="qwertyuiopasdfghjklzxcvbnm";
for (var i=0;i<subChar.length;i++)
{
if(findChar.indexOf(subChar.charAt(i))==-1)
{
alert("你输入的字符合法");
return;
}
}
alert("你输入的字符不合法")
}
</script>
</head>
<body>
<form action="" method="post" name="myform" id="myform">
<input type="text" name="txtString">
<input type="button" value="检查" onclick="isRight(document.myform.txtString.value)">
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>日期格式</title>
<script>
var now=new.Date();
document.write("当前时间是"+now.toLocaleFormat("%Y-%m-%d %p %H:%M:%S %a"));
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>加减日期</title>
<script>
var now=new Date();
var nationalDay=new Date(2023,10,1,0,0,0);
var msel=nationalDay-now;
document.write(msel+"毫秒<br>");
document.write(parseInt(msel/(24*60*60*1000))+"天");
</script>
</head>
<body>
</body>
</html>
更多推荐

所有评论(0)