yui 可靠的檢測輸入框的變化

可靠地檢測輸入框變化javascript

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8">
</head>
<body>
<p>11</p>
<form id="form1">
    <input type="text" id="demo" data-id="111" value="" />
</form>
<p>33</p>
<p>44</p>
<p>55</p>
<p id="m6">66</p>
<script src="http://yui.yahooapis.com/3.15.0/build/yui/yui-min.js"></script>
<script type="text/javascript">
(function() {
    YUI().use('event-valuechange', function(Y) {
        // 可靠地檢測輸入框變化
        Y.one('#demo').on('valueChange', function(ev) {
            Y.log('原來的值: ' + ev.prevVal + " 新值: " + ev.newVal);
            if (isNaN(Number(ev.newVal))) {
                Y.one('#demo').set('value', ev.prevVal);
            }
        });
    });
} ());
</script>
</body>
</html>
相關文章
相關標籤/搜索