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>