js 总括出数组中持有数字的和

作者:分分快三计划

$('#demo').on('click','span',(event)=>{
  let Url2 = event.currentTarget.offsetParent.childNodes[0].nodeValue;//获取点击的span的父成分的剧情
  let oInput = document.createElement('input'卡塔尔(英语:State of Qatar);//成立一个input
  oInput.value = Url2;
  document.body.appendChild(oInput);
  oInput.select(卡塔尔(قطر‎; // 选拔对象
  document.execCommand("Copy"卡塔尔(英语:State of Qatar); // 施行浏览器复制命令
  oInput.className = 'oInput';
  oInput.style.display='none';
})

<title>求出数组中有着数字的和</title>
<style>
body{color:#999;font:12px/1.5 Tahoma;}
#outer{width:500px;margin:0 auto;}
#outer input{padding:3px;border:1px solid #ccc;font-family:inherit;width:220px;margin-right:10px;}
.sum{font-size:30px;color:red;}
</style>
<script>
window.onload = function ()
{
 var oBtn = document.getElementsByTagName("button")[0];
分分快三计划, var oInput = document.getElementsByTagName("input")[0]
 var oStrong = document.getElementsByTagName("strong")[0];
 oInput.onkeyup = function ()
 {
  this.value = this.value.replace(/[^(d)|(,)]/,"")
 } 
 oBtn.onclick = function ()
 {
  var sum = 0;
  var oInput = document.getElementsByTagName("input")[0].value.split(",");
  for (var i in oInput)
  {
   sum = parseInt(oInput[i])
  }
  oStrong.innerHTML = sum
 }
}
</script>
</head>
<body>
<div id="outer">
    <label><input type="text" value="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15" /><span>输入数字求和,数字之间用半角","号分隔</span></label>
    <p><button>求和</button></p>
    <strong class="sum"></strong>
</div>

您可能感兴趣的篇章:

  • java顾客名密码验证示例代码分享
  • javasript兑现密码的隐没与浮现
  • Java随机生成手提式有线电话机短信验证码的法子
  • java web激活邮箱并找回密码
  • Java随机密码生成并和邮箱、手提式有线电话机号相称

<div id='demo'>作者正是被复制的从头到尾的经过<span>点击复制<span></div>

<body>
    <input type="password" value="" maxlength="16" />
    <div id="tips">
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </div>
</body>

帮衬宽容chrome/ FF/ IE>9/ Safari新版

 代码如下

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ";
<html xmlns=";

 

var arr = [1, 2, 3, 4, 5, 6];

  •             1卡塔尔(英语:State of Qatar)任何少于6个字符的重新组合,弱;任何字符数的同类字符组合,弱;
                2卡塔尔(英语:State of Qatar) 任何字符数的两类字符组合,中;
                3卡塔尔(英语:State of Qatar) 十二人字符数以下的三类或四类字符组合,强;
                4卡塔尔(英语:State of Qatar) 十三个人字符数以上的三类或四类字符组合,非常好。
                -------------------------------------------------------
  •             **/
            //检查评定密码强度
            function checkStrong(sValue) {
                var modes = 0;
                if (sValue.length < 6) return modes;
                if (/d/.test(sValue)) modes ; //数字
                if (/[a-z]/.test(sValue)) modes ; //小写
                if (/[A-Z]/.test(sValue)) modes ; //大写 
                if (/W/.test(sValue卡塔尔(英语:State of Qatar)卡塔尔(قطر‎ modes ; //特殊字符
                switch (modes) {
                case 1:
                    return 1;
                    break;
                case 2:
                    return 2;
                case 3:
                case 4:
                    return sValue.length < 12 ? 3 : 4
                    break;
                }
            }
        </script>
    </head>

join函数

</html>

join函数 代码...

            oInput.onkeyup = oInput.onfocus = oInput.onblur = function() {
                var index = checkStrong(this.value);
                this.className = index ? "correct": "error";
                oTips.className = "s" index;
                for (i = 0; i < aSpan.length; i ) aSpan[i].className = aSpan[i].innerHTML = "";
                index && (aSpan[index - 1].className = "active", aSpan[index - 1].innerHTML = aStr[index - 1])
            }
        };
        /** 强度法则
            -------------------------------------------------------

 代码如下

复制代码 代码如下:

复制代码

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>
        密码强度检查实验
    </title>
    <style type="text/css">
        body{font:12px/1.5 Arial;} input{float:left;font-size:12px;width:150px;font-family:arial;border:1px
        solid #ccc;padding:3px;} input.correct{border:1px solid green;} input.error{border:1px
        solid red;} #tips{float:left;margin:2px 0 0 20px;} #tips span{float:left;width:50px;height:20px;color:#fff;overflow:hidden;background:#ccc;margin-right:2px;line-height:20px;text-align:center;}
        #tips.s1 .active{background:#f30;} #tips.s2 .active{background:#fc0;} #tips.s3
        .active{background:#cc0;} #tips.s4 .active{background:#090;}
    </style>
    <script type="text/javascript">
        window.onload = function() {
            var oTips = document.getElementById("tips");
            var oInput = document.getElementsByTagName("input")[0];
            var aSpan = oTips.getElementsByTagName("span");
            var aStr = ["弱", "中", "强", "非常好"];
            var i = 0;

var value = eval(arr.join(" "));

自然大家仍然为能够动用遍历的办法

复制代码

前几天赶上四个总计数组求和的主题材料,总认为for循环求和劳动,搜了后生可畏晃,以为那么些措施还不易,只是那其间的eval不知底好不佳

本文由分分快三计划发布,转载请注明来源

关键词: 分分快三计划