YUI3 输入整数的验证

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>

</head>
<body>
<input type="text" id="demo" value="" maxlength="10" size="10"/>
<script src="/yui/build/yui/yui-min.js"></script>
<script type="text/javascript">

    YUI().use('node', function(Y) {

        function inputIntValid() {
            var node = Y.one('#demo'), nodeValue = node.get('value'),
                    inNodeValue = parseInt(nodeValue);

            if (!isNaN(nodeValue)) {
                if (inNodeValue !== 0) {
                    node.setAttribute('d-b-v', inNodeValue);
                    node.set('value', node.getAttribute('d-b-v'));
                } else {
                    node.set('value', node.getAttribute('d-b-v'));
                }
            } else {
                node.set('value', node.getAttribute('d-b-v'));
            }
        }

        Y.one('#demo').on(['keyup', 'blur'], inputIntValid);
    });

</script>
</body>
</html>

 

 

 

posted @ 2014-04-24 09:34  wheats  阅读(119)  评论(0编辑  收藏  举报