标签:
<html> <!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"> <head> <meta http-equiv="Content-Type" content="text/html" charset="gb2312"> <title>my second javascript file</title> </head> <body> hello,world! <br/> <div style="background:pink;width:300px;height:400px;"> <from action="" method="" id="form1"> <p> <label for="beforenum">请输入要格式化的数字:</br> <input name="beforenum" type="text" id="beforenum" ></input> </label> </p> <p> <label for="numlength">请输入要格式化的数字的长度:</br> <input name="numlength" type="text" id="numlength" ></input> </label> </p> <p> <label for="afternum">格式化后的数字:</br> <input name="afternum" type="text" id="afternum"></input> </label> </p> <input name="submit" type="button" class="" onClick="formatNo(document.getElementById(‘beforenum‘).value,document.getElementById(‘numlength‘).value);" value="转换"/> <input name="cancel" type="button" class="" value="取消"/> </form> </div> <script language="javascript"> //输出变量类型 var typea=3; var typeb="name"; var typec=null; Objecta=new Object(); document.writeln("<pre>a的类型为"+(typeof typea)+"\nb的类型为"+(typeof typeb)+"\nObject1的类型为"+(typeof Objecta)+"</pre>"); //条件运算符 var a=20; var b=20; document.writeln(a!=b)?true:false; document.writeln("<pre>我喜欢学习 javascript!!!\n"); //new运算符 Object1=new Object(); Array2=new Array(); Date3=new Date("May 21 2015") document.writeln(Date3.getFullYear()+"</pre>");//如果是Month必须加1,因为月是从0开始的 //大小写转换 var myString=new String("Xinqing wil be Happy!"); var lower=myString.toLowerCase(); var upper=myString.toUpperCase(); document.writeln("myString转换为大写字母是"+upper); //将数字格式化为指定长度 //在按“转换”按钮时调用函数,带参调用 function formatNo(str1,len1) { if(len1==""||str1==""){ alert("请输入数字和长度"); } alert("长度"+len1+";字符"+str1+";"); var strLen=str1.length; alert("长度"+len1+";字符"+strLen+";"); for(i=0;i<len1-strLen;i++) { str1="0"+str1; } var afternum1=document.getElementById("afternum") //alert(str1); afternum1.value=str1; } </script> </body> </html>
标签:
原文地址:http://www.cnblogs.com/sunshine-habit/p/4896519.html