AngularJS:标签中 class="" 和 ng-click="" 的优先顺序
AngularJS: preferable order of class="" and ng-click="" within a tag
之间有什么偏好吗
<button class="btn" ng-click="superalert()" title="">Show alert</button>
<button ng-click="superalert()" class="btn" title="">Show alert</button>
我看不出有什么不同,但可能存在一些偏好或棘手的陷阱。
因此 HTML 不规定属性的顺序。但为了您自己的利益,我建议您坚持一个标准。我看到了关于这个主题的类似讨论,您可能会发现类似行的价值 - valid order for attributes of input type tag. There is one response in that discussion that points to a page on conventions containing attribute order. These conventions are from Mark Otto。我看到没有关于 AngularJS 属性的详细信息,因此我将修改这些约定以满足所用技术堆栈的需求(在您的情况下为 Angular)。
没有必需的顺序 -- 您可以按照自己喜欢的顺序进行操作。
我通常优先选择id
、class
、name
等(标准HTML属性),其次是ng-___
属性。我将 Angular 属性按字母顺序排列只是为了在元素有多个属性时简化查找特定属性的过程。
<button class="btn" ng-click="superalert()" title="">Show alert</button>
<button ng-click="superalert()" class="btn" title="">Show alert</button>
我看不出有什么不同,但可能存在一些偏好或棘手的陷阱。
因此 HTML 不规定属性的顺序。但为了您自己的利益,我建议您坚持一个标准。我看到了关于这个主题的类似讨论,您可能会发现类似行的价值 - valid order for attributes of input type tag. There is one response in that discussion that points to a page on conventions containing attribute order. These conventions are from Mark Otto。我看到没有关于 AngularJS 属性的详细信息,因此我将修改这些约定以满足所用技术堆栈的需求(在您的情况下为 Angular)。
没有必需的顺序 -- 您可以按照自己喜欢的顺序进行操作。
我通常优先选择id
、class
、name
等(标准HTML属性),其次是ng-___
属性。我将 Angular 属性按字母顺序排列只是为了在元素有多个属性时简化查找特定属性的过程。