JavaScript
Java实现小写金额转换为大写金额
package com.share.test;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String je = "零壹贰叁肆伍陆柒捌玖";
String cdm = "万仟佰拾亿仟佰拾万仟佰拾元角分";
while (true) {
System.out.println("请输入金额:");
String money = input.next();
int newstring_je = (int) (Double.valueOf(money).doubleValue() * 100);// 将金额值乘以100
int newstringlength = String.valueOf(newstring_je).length();// 乘以100之后的金额的长度
String newstring = String.valueOf(newstring_je);
String newdw = cdm.substring(cdm.length() - newstringlength);
System.out.println("第一次裁剪之後的值為:" + newdw);
int num0 = 0;// 记录0出现的个数
int wan = 0;// 记录万位出现的个数
String dxje = "";// 记录大写金额
for (int i = 0; i < newstringlength ; i++) {
String xiaoxie = newstring.substring(i,i+1);
String daxie = je.substring(Integer.parseInt(xiaoxie),Integer.parseInt(xiaoxie)+1);
String danwei = newdw.substring(i, i+1);
if(daxie.equals("零")){
daxie="";
if(danwei.equals("亿")){
}else if(danwei.equals("万")){
daxie="";
wan = 1;
}else if(danwei.equals("元")){
}else {
danwei="";
}
num0++;
}else{
if(num0-wan>0){
if(!danwei.equals("角")){
daxie = "零"+daxie;
}
}
num0=0;
}
dxje += daxie+danwei;
}
if(newstring.length()!=1){
if(newstring.substring(newstring.length()-2).equals("00")){
dxje+="整";
}
}
System.out.println("大写金额为:"+dxje);
}
}
}
JS实现小写金额转换为大写金额
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>小写金额转换为大写金额</title>
<script language="javaScript">
function convert(){
var money_num = document.getElementById("money_num").value;
if(money_num==""){
alert("请输入金额!");
document.getElementById("money_num").focus();
return;
}
if(isNaN(money_num)){
alert("请输入数字类型的金额 !");
return;
}
if(money_num>999999999999){
alert("您输入的金额不能大于999999999999!");
return;
}
//将小数点后保留两位小数
if(money_num.indexOf(".")>0){
var decimalStr = money_num.split(".");
if(decimalStr[1].length>2){
decimalStr[1]=decimalStr[1].substr(0,2);
}
money_num = decimalStr[0]+"."+decimalStr[1];
}
value=change(money_num); //调用自定义函数转换
document.getElementById("money_cn").value=value; //将转换后的值赋给文本框
}
function change(str){
je="零壹贰叁肆伍陆柒捌玖"; //大写的数字(0-9)
cdw="万仟佰拾亿仟佰拾万仟佰拾元角分"; //金额单位
var newstring=(str*100).toString(); //将金额值乘以100
alert(newstring);
newstringlog=newstring.length; //乘以100之后的金额的长度
newdw=cdw.substr(cdw.length-newstringlog);
num0=0; //记录零的个数
wan=0; //记录万位出现的次数
dxje=""; //记录大写金额
for(m=1;m<newstringlog+1;m++){
xzf=newstring.substr(m-1,1); //String.substr(index,length) :index-开始截取下标,length:截取的长度
dzf=je.substr(xzf,1);
dw=newdw.substr(m-1,1);
if(dzf=="零"){
dzf="";
if(dw=="亿"){
}else if(dw=="万"){
dzf="";
wan=1;
}else if(dw=="元"){
}else{
dw=""; //记录单位
}
num0=num0+1;
}else{
if(num0-wan>0){
if(dw!="角"){
dzf="零"+dzf;
}
}
num0=0;
}
dxje=dxje+dzf+dw;
}
if(newstring.length!=1){
if(newstring.substr(newstring.length-2)=="00"){
dxje=dxje+"整";
}else{
dxje=dxje;
}
}
return dxje;
}
/*
将输入的金额转化为大写形式
1、获取输入的金额的值
2、判断这个金额是否符合显示条件【范围,小数的位数】
3、获取这个金额最大位数
4、从最大的位数开始,依次匹配例如:123.12 1->壹->佰:壹佰
5、优化处理,多个零的处理,及元和角之间的区分
6、显示
*/
</script>
<style type="text/css">
table{
font-size: 20px;
font-family: 楷体;
color:navy;
}
input{
font-size: 20px;
font-family: 楷体;
color:navy;
}
font{
font-size: 19px;
font-family: 楷体;
color:orangered;
}
</style>
</head>
<body>
<form action="" id="myform">
<table align="center">
<tr>
<td>请输入小写金额:</td>
</tr>
<tr>
<td>
<input type="text" id="money_num" size="40">
</td>
</tr>
<tr>
<td>转换后的大写金额:</td>
</tr>
<tr>
<td>
<textarea rows="5" cols="35" id="money_cn"></textarea>
</td>
</tr>
<tr>
<td align="center">
<input type="button" value="转 换" οnclick="convert()">
</td>
</tr>
</table>
</form>
</body>
</html>
JavaScript:当输入字段获得焦点时,会触发改变背景颜色的函数。
<html>
<head>
<script>
function myFunction(x)
{
x.style.background="yellow";
}
function myFunction1(x){
x.style.background="white";
}
</script>
</head>
<body>
请输入英文字符:<input type="text" οnfοcus="myFunction(this)" οnblur="myFunction1(this)">
<p>当输入字段获得焦点时,会触发改变背景颜色的函数。</p>
</body>
</html>
Javascript:刮刮乐
<html>
<body>
<div
οnmοuseοver="mOver(this)"
οnmοuseοut="mOut(this)"
style="background-color:#D94A38;width:200px;height:50px;padding-top:25px;text-align:center;">
刮开有奖
</div>
<script>
function mOver(x)
{
x.innerHTML="谢谢你"
}
function mOut(x)
{
x.innerHTML="把鼠标指针移动到上面"
}
</script>
</body>
</html>
Javascript:生份证验证
<!DOCTYPE html>
<html>
<head><title>idcard 验证</title></head>
<script type="text/javascript">
function checkIDCard(){
var IDCard = document.getElementById("IDCard");
var regIDCard_15=/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0|1])\d{3}$/;
var regIDCard_18=/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0|1])\d{3}[\d|x|X]$/;
if(IDCard.value.length!=15&&IDCard.value.length!=18){
alert("您输入的省份证号码长度不对,请输入15位或18位的身份证号码");
IDCard.focus();
return;
}else{
if(IDCard.value.length==15){
if(!regIDCard_15.test(IDCard.value)){
alert("您输入的省份证号码有误!");
IDCard.focus();
return;
}
}
if(IDCard.value.length==18){
if(!regIDCard_18.test(IDCard.value)){
alert("您输入的省份证号码有误!");
IDCard.focus();
return;
}
}
}
alert("输入正确");
document.getElementById("myform").submit();
}
</script>
<style type="text/css">
table{
font-size:13px;
font-family:楷体;
color:navy;
}
input{
font-size:13px;
font-family:楷体;
color:navy;
}
font{
font-size:12px;
font-family:楷体;
color:orangered;
}
</style>
<body>
<form method="" action="http://www.baidu.com" id="myform">
<table align="center">
<tr>
<td>姓名:<input type="text" id="user"></td>
</tr>
<tr>
<td>密码:<input type="password" id="password"</td>
</tr>
<tr>
<td>身份证号码:<input type="text" id="IDCard"</td>
</tr>
<tr>
<td><input type="button" value="提交" onClick="checkIDCard()"></td>
</tr>
</table>
</form>
</body>
</html>