码迷,mamicode.com
首页 > 其他好文 > 详细

所有文本框都不为空时,提交按钮变色

时间:2014-12-05 22:33:23      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   for   on   div   

因为商城项目的需求,自己写了一个小例子。

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        input {
            display: block;
            margin: 1em;
        }

        button {
            margin: 1em;
            color:#fff;
            background:#999;
            border:none;
        }
    </style>
    <script src="../library/zepto.all.min.js"></script>
</head>
<body>
<input type="text" class="test" id="test1"/>
<input type="text" class="test" id="test2"/>
<input type="text" class="test" id="test3"/>
<button id="testBtn">button</button>
<script>
    var test1 = document.getElementById(test1);
    var test2 = document.getElementById(test2);
    var test3 = document.getElementById(test3);
    var testBtn = document.getElementById(testBtn);
    var flag = false;
    var arr = [];
    arr.push(test1);
    arr.push(test2);
    arr.push(test3);
    arr.forEach(function (ele) {
        ele.addEventListener(blur, function () {
            flag = arr.every(function (obj) {
                return obj.value !== ‘‘;
            });
            if(flag){
                testBtn.style.backgroundColor = green;
            } else {
                testBtn.style.backgroundColor = #999;
            }
        }, false);
    });
</script>
</body>
</html>

 

所有文本框都不为空时,提交按钮变色

标签:style   blog   io   ar   color   sp   for   on   div   

原文地址:http://www.cnblogs.com/lixiaoyaoslove/p/4147521.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!