JS之经典代码段
来源:互联网 发布:保险网络继续教育 编辑:程序博客网 时间:2024/04/28 12:47
小写金额与大写金额联动
获取文本框里鼠标选取到的文字
复选框的全选,多选,全不选,反选
- <script language="JavaScript">
- function daxie()
- {
- this.values = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
- this.digits = ["", "拾", "佰", "仟"];
- }
- function daxie.prototype.getdx(num)
- {
- if(isNaN(num)) return "";
- var number = Math.round(num*100)/100;
- number = number.toString(10).split('.');
- var integer = number[0];
- var len = integer.length;
- if (len > 12)
- return "数值超出范围!支持的最大数值为 999999999999.99";
- var returnValue = this.bns(integer.slice(-4));
- if (len > 4)
- returnValue = this.bns(integer.slice(-8,-4)) + (integer.slice(-8,-4)!="0000"?"万":"") + returnValue;
- if (len > 8)
- returnValue = this.bns(integer.slice(-12,-8)) + "亿" + returnValue;
- if(returnValue!="")
- returnValue += "圆";
- if(number.length==2)
- {
- var cok = number[1].split('');
- if(returnValue!="" || cok[0]!="0")
- returnValue += this.values[parseInt(cok[0])] + (cok[0]!="0"?"角":"");
- if(cok.length>=2)
- returnValue += this.values[parseInt(cok[1])] + "分";
- }
- if(returnValue!="" && !/分$/.test(returnValue))
- returnValue += "整";
- return returnValue;
- }
- function daxie.prototype.bns(str)
- {
- var num = str.split('');
- var dsl = num.length-1;
- var returnValue = "";
- for (var i=0; i<=dsl; i++)
- returnValue += this.values[parseInt(num[i])] + (num[i]!='0'?this.digits[dsl-i]:"");
- returnValue = returnValue.replace(/零+$/, "").replace(/零{2,}/, "零");
- return returnValue;
- }
- //////////////////////////////////////////////
- var stmp = "";
- var dfs = new daxie();
- function nst(t)
- {
- if(t.value==stmp) return;
- var ms = t.value.replace(/[^/d/.]/g,"").replace(/(/./d{2}).+$/,"$1");
- var txt = ms.split(".");
- while(//d{4}(,|$)/.test(txt[0]))
- txt[0] = txt[0].replace(/(/d)(/d{3}(,|$))/,"$1,$2");
- t.value = stmp = txt[0]+(txt.length>1?"."+txt[1]:"");
- bbb.innerHTML ="<font color=red>"+dfs.getdx(parseFloat(ms))+"</font>";
- }
- </script>
- 小写金额:<input type="text" name="aaa" onkeyup="nst(this)"><br>
- 大写金额: <SPAN id="bbb"> </SPAN>
获取文本框里鼠标选取到的文字
- <textarea rows="10" cols="50" id="t1">
- 请问如何获得 文本框里 鼠标选取到的文字?
- </textarea>
- <br>
- <button onClick="if (document.selection.createRange().text != '') t1.value
- = t1.value.replace(document.selection.createRange().text, '<b>' + document.selection.createRange().text + '</b>')">
- <b> B </b></button>
- <button onClick="if (document.selection.createRange().text != '') t1.value
- = t1.value.replace(document.selection.createRange().text, '<i>' + document.selection.createRange().text + '</i>')"><i> I </i></button>
复选框的全选,多选,全不选,反选
- <form name=hrong>
- <input type=checkbox name=All onclick="checkAll('mm')">全选<br/>
- <input type=checkbox name=mm onclick="checkItem('All')"><br/>
- <input type=checkbox name=mm onclick="checkItem('All')"><br/>
- <input type=checkbox name=mm onclick="checkItem('All')"><br/>
- <input type=checkbox name=mm onclick="checkItem('All')"><br/>
- <input type=checkbox name=mm onclick="checkItem('All')"><br/><br/>
- <input type=checkbox name=All2 onclick="checkReverse('mm2')">反选<br/>
- <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
- <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
- <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
- <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
- <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
- <input type=checkbox name=All3 onclick="checkItem('mm3')">特选<br/>
- <input type=checkbox name=mm3 onclick="checkItem('All3')"><br/>
- </form>
- <SCRIPT LANGUAGE="JavaScript">
- function checkAll(str)
- {
- var a = document.getElementsByName(str);
- var n = a.length;
- for (var i=0; i<n; i++)
- a[i].checked = window.event.srcElement.checked;
- }
- function checkReverse(str)
- {
- var a = document.getElementsByName(str);
- var n = a.length;
- for (var i=0; i<n; i++)
- a[i].checked = !a[i].checked;
- }
- function checkItem(str)
- {
- var e = window.event.srcElement;
- var all = eval("document.hrong."+ str);
- if (e.checked)
- {
- var a = document.getElementsByName(e.name);
- all.checked = true;
- for (var i=0; i<a.length; i++)
- {
- if (!a[i].checked){ all.checked = false; break;}
- }
- }
- else all.checked = false;
- }
- </SCRIPT>
- JS之经典代码段
- JS之经典代码段
- 经典的js 代码段
- 几段经典的js代码解析
- JS之经典代码段续二
- JS之经典代码段续二
- JavaScript经典代码段
- jsp经典代码段
- js综合代码段
- 代码段-JS路由
- 常用JS代码段
- JS代码段记录
- 代码段之RSS
- C#入门 二十五段经典代码
- 50个经典CSS代码段
- 经典js代码收藏
- 经典asp、js代码
- JS 经典代码收藏
- 在WIN2000中图片不能进行“缩略图”,怎么解决?
- JS键盘控制事件教程
- 关于java中JDK5的打包,拆包以及"=="和equals的问题
- 飞信和QQ的CMD命令行接口
- JS屏蔽键盘
- JS之经典代码段
- mysql delimiter用法
- 各种语言码
- js判断键盘按键
- Effective C#之Item 26: Implement Ordering Relations with IComparable and IComparer
- Flex-Jsp-Mysql简单结合例子
- 针对一直让我失望的华硕,我彻底无语
- javascrit中的栈
- 检测并排除内存泄漏