国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

angular.js - There are both angular and jquery plugins to handle keydown events
漂亮男人
漂亮男人 2017-05-15 17:08:07
0
2
749

I downloaded a jq plug-in online, and the input box is bound to the click event, but the angular script I wrote myself also uses ng-keydown on the same input box. . . I thought Angular's keydown processing function would be executed, but it didn't work. . . But I can't remove the click event handler of the plug-in because its function needs to be used. . . Don’t know how to deal with this situation

漂亮男人
漂亮男人

reply all(2)
給我你的懷抱

<body ng-app="myApp" ng-controller="MyController">

<!--自定義指令: 限制輸入框中只能是1到100之間的數(shù)值-->
<input type="text" score>
<script type='text/javascript' src="angular.js"></script>
<script type="text/javascript">

angular.module('myApp',[])

            .directive('score', function () {
                return {
                    link : function (scope, elements, attrs, controller) {  //在顯示之前執(zhí)行, 只執(zhí)行一次
                        //得到input
                        //console.log('link()',elements);
                        var input = elements[0]
                        //給input綁定keyup的監(jiān)聽回調(diào)函數(shù)
                        input.onkeyup = function () {
                            //讀取input的value, 判斷是否合法
                            var score = input.value.trim()
                            //如果合法, background為white
                            if(score==='' || (score*1>=1&&score*1<=100)) {
                                input.style.background = 'white'
                            } else {
                                //否則為red
                                input.style.background = 'red'
                            }
                        }
                    }
                }
            })
            .controller('MyController', function($scope){

            });
            

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

The keyup event I just wrote today, keydown is similar

僅有的幸福

You can’t write it like this,
The first choice is require: '?ngModel',
Then get the value of the text box ngModel.$modelValue instead of input.value,
There is also no need for elements [0], element represents
jquery The thinking is too serious. . .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template