gpt4 book ai didi

javascript - 如何修复括号与点符号 Angularjs

转载 作者:行者123 更新时间:2023-12-02 16:27:27 25 4
gpt4 key购买 nike

问题很简单,我认为下面的代码更好解释

//指令

.directive('special', function(){
return {
restrict: 'A',
link: function(scope, element, attrs){
element.on('focus', function(){
element.removeClass('error-form');

scope.$apply(function(){
alert(attrs.personal); //prints out 'INVALID_NAME'
scope.errors.INVALID_NAME = false; //updates as I'd like
scope.errors[attrs.personal] = false; //Should do the same as above but isn't
});

});
}
};
})

//字段中的代码(html)

personal="'INVALID_NAME'"

我想使用括号符号,因为它将是一个可重用的指令,我必须在很多字段上使用。但它不起作用。我究竟做错了什么?谢谢

最佳答案

变量attrs.personal的内容有一对额外的引号。将其更改为

personal = "INVALID_NAME"

它会起作用。

关于javascript - 如何修复括号与点符号 Angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28568120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com