我使用AngularJS v1.2.3和jQuery 1.7.1,这些库按照以下顺序包含:
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="angular.min.js"></script>
以下脚本工作方式有些奇怪,Firebug 显示第二项具有属性 "selected",但我看到的是第一项被选中!
<select ng-app>
<option value="1" ng-selected="3==1">#1</option>
<option value="2" ng-selected="2==2">#2</option>
<option value="3" ng-selected="1==3">#3</option>
</select>
当我改变脚本的排序顺序(angularjs在jquery之前),代码按预期工作。
我必须做什么来防止这个问题?我不能改变脚本的排序顺序。
更新: 这是jQuery 1.7.1的一个错误:
// See #9699 for explanation of this approach (setting first, then removal)
jQuery.attr( elem, name, "" );
后来问题被修复了:
// Do not do this for boolean attributes (see #10870)
if ( !isBool ) {
jQuery.attr( elem, name, "" );
}