[英]Selecting elements in jQuery
In continuation of the question at this link I wanted to add some functionality in test.html 在此链接上继续提问时,我想在test.html中添加一些功能
The event trigger is 'clicking' on any <p class=""> tag. 事件触发器是在任何<p class =“”>标签上“单击”的。 After clicking I wanted that particular <p> to disappear (which was fairly straightforward)
but I also want that
单击后,我希望特定的<p>消失(这很简单), 但我也希望
I tried to go about the thing with my knowledge of jQuery selectors and the selector documentation avaliable, but didn't reach anywhere near what I want. 我尝试着用我对jQuery选择器和选择器文档的了解来解决问题,但是没有达到我想要的目标。 This is what I have done till now.
这是我到目前为止所做的。
$('p.*').live('click', function() {
$(this).hide('slow');
if( $('p').is(':hidden') ) {
$('.shower').show();
}
if( $('p.*').is(':hidden') ) {
$('.hider').show();
}
});
However This code does not selectively toggle at the extreme conditions of all <p> hidden 但是,此代码不会在所有<p>隐藏的极端条件下有选择地切换
Here's a way to do it 这是一种方法
var all_ps = $('p.*').length;
var hidden_ps = 0;
$('p.*').live('click', function() {
$(this).hide('slow');
hidden_ps++;
updateButtons();
});
function updateButtons()
{
$('.hider').show();
$('.shower').show();
if(hidden_ps == all_ps-1) {
$('.hider').hide();
} else if(hidden_ps == 0) {
$('.shower').hide();
}
}
function resetButtons()
{
$('p.*').show();
hidden_ps = 0;
updateButtons()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.