JS之经典代码段

小写金额与大写金额联动
  1. <script language="JavaScript">
  2. function daxie()
  3. {
  4. this.values = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
  5. this.digits = ["", "拾", "佰", "仟"];
  6. }
  7. function daxie.prototype.getdx(num)
  8. {
  9. if(isNaN(num)) return "";
  10. var number = Math.round(num*100)/100;
  11. number = number.toString(10).split('.');
  12. var integer = number[0];
  13. var len = integer.length;
  14. if (len > 12)
  15. return "数值超出范围!支持的最大数值为 999999999999.99";
  16. var returnValue = this.bns(integer.slice(-4));
  17. if (len > 4)
  18. returnValue = this.bns(integer.slice(-8,-4)) + (integer.slice(-8,-4)!="0000"?"万":"") + returnValue;
  19. if (len > 8)
  20. returnValue = this.bns(integer.slice(-12,-8)) + "亿" + returnValue;
  21. if(returnValue!="")
  22. returnValue += "圆";
  23. if(number.length==2)
  24. {
  25. var cok = number[1].split('');
  26. if(returnValue!="" || cok[0]!="0")
  27. returnValue += this.values[parseInt(cok[0])] + (cok[0]!="0"?"角":"");
  28. if(cok.length>=2)
  29. returnValue += this.values[parseInt(cok[1])] + "分";
  30. }
  31. if(returnValue!="" && !/分$/.test(returnValue))
  32. returnValue += "整";
  33. return returnValue;
  34. }
  35. function daxie.prototype.bns(str)
  36. {
  37. var num = str.split('');
  38. var dsl = num.length-1;
  39. var returnValue = "";
  40. for (var i=0; i<=dsl; i++)
  41. returnValue += this.values[parseInt(num[i])] + (num[i]!='0'?this.digits[dsl-i]:"");
  42. returnValue = returnValue.replace(/零+$/, "").replace(/零{2,}/, "零");
  43. return returnValue;
  44. }
  45. //
  46. var stmp = "";
  47. var dfs = new daxie();
  48. function nst(t)
  49. {
  50. if(t.value==stmp) return;
  51. var ms = t.value.replace(/[^/d/.]/g,"").replace(/(/./d{2}).+$/,"$1");
  52. var txt = ms.split(".");
  53. while(//d{4}(,|$)/.test(txt[0]))
  54. txt[0] = txt[0].replace(/(/d)(/d{3}(,|$))/,"$1,$2");
  55. t.value = stmp = txt[0]+(txt.length>1?"."+txt[1]:"");
  56. bbb.innerHTML ="<font color=red>"+dfs.getdx(parseFloat(ms))+"</font>";
  57. }
  58. </script>
  59. 小写金额:<input type="text" name="aaa" οnkeyup="nst(this)"><br>
  60. 大写金额: <SPAN id="bbb"> </SPAN>


获取文本框里鼠标选取到的文字

  1. <textarea rows="10" cols="50" id="t1">
  2. 请问如何获得 文本框里 鼠标选取到的文字?
  3. </textarea>
  4. <br>
  5. <button onClick="if (document.selection.createRange().text != '') t1.value
  6. = t1.value.replace(document.selection.createRange().text, '<b>' + document.selection.createRange().text + '</b>')">
  7. <b> B </b></button>
  8. <button onClick="if (document.selection.createRange().text != '') t1.value
  9. = t1.value.replace(document.selection.createRange().text, '<i>' + document.selection.createRange().text + '</i>')"><i> I </i></button>


复选框的全选,多选,全不选,反选

  1. <form name=hrong>
  2. <input type=checkbox name=All οnclick="checkAll('mm')">全选<br/>
  3. <input type=checkbox name=mm οnclick="checkItem('All')"><br/>
  4. <input type=checkbox name=mm οnclick="checkItem('All')"><br/>
  5. <input type=checkbox name=mm οnclick="checkItem('All')"><br/>
  6. <input type=checkbox name=mm οnclick="checkItem('All')"><br/>
  7. <input type=checkbox name=mm οnclick="checkItem('All')"><br/><br/>
  8. <input type=checkbox name=All2 οnclick="checkReverse('mm2')">反选<br/>
  9. <input type=checkbox name=mm2 οnclick="checkItem('All2')"><br/>
  10. <input type=checkbox name=mm2 οnclick="checkItem('All2')"><br/>
  11. <input type=checkbox name=mm2 οnclick="checkItem('All2')"><br/>
  12. <input type=checkbox name=mm2 οnclick="checkItem('All2')"><br/>
  13. <input type=checkbox name=mm2 οnclick="checkItem('All2')"><br/>
  14. <input type=checkbox name=All3 οnclick="checkItem('mm3')">特选<br/>
  15. <input type=checkbox name=mm3 οnclick="checkItem('All3')"><br/>
  16. </form>
  17. <SCRIPT LANGUAGE="JavaScript">
  18. function checkAll(str)
  19. {
  20. var a = document.getElementsByName(str);
  21. var n = a.length;
  22. for (var i=0; i<n; i++)
  23. a[i].checked = window.event.srcElement.checked;
  24. }
  25. function checkReverse(str)
  26. {
  27. var a = document.getElementsByName(str);
  28. var n = a.length;
  29. for (var i=0; i<n; i++)
  30. a[i].checked = !a[i].checked;
  31. }
  32. function checkItem(str)
  33. {
  34. var e = window.event.srcElement;
  35. var all = eval("document.hrong."+ str);
  36. if (e.checked)
  37. {
  38. var a = document.getElementsByName(e.name);
  39. all.checked = true;
  40. for (var i=0; i<a.length; i++)
  41. {
  42. if (!a[i].checked){ all.checked = false; break;}
  43. }
  44. }
  45. else all.checked = false;
  46. }
  47. </SCRIPT>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值