Angularjs 角度jqLite:.find()赢了';t工作-不选择标记
我有一个茉莉花的单位规格:Angularjs 角度jqLite:.find()赢了';t工作-不选择标记,angularjs,jasmine,jqlite,Angularjs,Jasmine,Jqlite,我有一个茉莉花的单位规格: define(['common/components/directives/directives', 'angular'], function (directives, ng) { describe('The directives module', function () { beforeEach(function () { ng.mock.module('directives'); }); describe('The t
define(['common/components/directives/directives', 'angular'], function (directives, ng) {
describe('The directives module', function () {
beforeEach(function () {
ng.mock.module('directives');
});
describe('The tabset directive', function () {
var scope;
var elm;
beforeEach(inject(function($rootScope, $compile) {
elm = ng.element('<tabset>' +
'<tab data-route="/home" data-title="Home"></tab>' +
'<tab data-route="/tournaments" data-title="Tournaments"></tab>' +
'<tab data-route="/about" data-title="About"></tab>' +
'</tabset>');
var scope = $rootScope;
$compile(elm)(scope);
scope.$digest();
}));
it ('should create clickable titles', function () {
var titles = elm.find('ul li a');
expect(titles.length).toBe(3);
expect(titles.eq(0).text()).toBe('Home');
expect(titles.eq(0).text()).toBe('Tournaments');
expect(titles.eq(0).text()).toBe('About');
});
//it ('should change active tab when clicked', function () {
//});
});
});
您不能使用
。这样查找方法。像这样使用它:
elm.find('a');
或:
看一看:你不能使用。这样找到方法。像这样使用它:
elm.find('a');
或:
查看:el.find()
尝试在el
的子元素、子元素等集合中查找元素。您尝试在元素中查找ul
,该元素本身就是ul
,并且只包含li
元素。此外,您不能在find
中使用子选择器。使用链式el.find('li').find('a')
。el.find()
尝试在el
的子元素、子元素等集合中查找元素。您尝试在ul
本身且仅包含li
元素的元素中查找ul
。此外,您不能在find
中使用子选择器。使用链式el.find('li')。find('a')
。谢谢,你应该意识到这一点。正如在其他答案中所说,你也可以直接搜索'a'
。谢谢,你应该意识到这一点。正如在其他答案中所说,你也可以直接搜索'a'
。
elm.find('ul').find('li').find('a');