2
我有以下HTML:Angularjs指令 - 一類名來選擇下一個元素
<div>
<input type="text" ng-model="search.q" special-input>
<ul class="hidden">...</ul>
<ul class="hidden bonus">...</ul>
</div>
與以下指令:
myApp.directive('specialInput', ['$timeout', function($timeout)
{
return {
link: function(scope, element) {
element.bind('focus', function() {
$timeout(function() {
// Select ul with class bonus
element.parent().find('.bonus').removeClass('hidden');
});
});
}
}
}]);
我要選擇使用jqLite的ul.bonus但不能想辦法。我嘗試使用.next(「。bonus」),但選擇器完全被忽略,並且選擇了第一個ul。有沒有人有一個想法,爲什麼我不能這樣做?
P.S.我只是依靠沒有jQuery的AngularJS內部jqLite。
謝謝!
謝謝,你說得對,這種方法好得多 – Angelin
嗨,但實際上如何使用jqlite按類選擇下一個元素?在我的情況下,我需要做,但不知道如何。到目前爲止,我沒有'link.parent()。next()。toggleClass('active');'這當然不能按預期工作。 jQuery相當於'link.parent()。siblings('.active')。toggleClass('active');'。感謝您的未來答案 – lkartono