84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
网上下了个jq插件,输入框绑定了click事件,但是我自己写的angular脚本也在同一个输入框上用了ng-keydown。。。我以为是angular的keydown处理函数会执行,结果没效果。。。但是我又不能把插件的click事件处理函数给去掉,因为要用到它的功能。。。不知道怎么处理这种情况
angular.module('myApp',[])
.directive('score', function () { return { link : function (scope, elements, attrs, controller) { //在显示之前执行, 只执行一次 //得到input //console.log('link()',elements); var input = elements[0] //给input绑定keyup的监听回调函数 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){ });
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 representsjquery The thinking is too serious. . .
angular.module('myApp',[])
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. . .