How can I invisiblize groups of controls via jQuery?

烂漫一生 提交于 2019-12-02 03:49:34
QBM5

there are a number of ways to do this. but in your jquery implementation I would decorate the elements with data tags that will tell the code which elements to hide and show.

<input data-group="1" type="text" />
<input data-group="2" type="text" />

var $group1 = $('*[data-group="1"]');
var $group2 = $('*[data-group="2"]');
if (ckd) {
  $group1.hide(); 
  $group2.show(); 
}
else{
 $group2.hide(); 
 $group1.show(); 
}

You could do the same thing with css classes as well but I prefer using the data attribute

If you can group your controls using classes, you could select the class which needs to be hidden in that particular scenario and just use the hide() function:

if (ckd) {
    var cls = getClassForCurrentScenario();
    $("." + cls).hide(); //slideUp() would be an animated alternative
}

If the controls can be grouped inside a div, for example, then you'd just need to hide that element:

if (ckd) {
    var id = getElementIdForCurrentScenario();
    $("#" + id).hide(); //slideUp() would be an animated alternative
}

It really depends on how you manage to group your controls into "target groups", so that you can efficiently access them later.

You can hide an element like so:

$('...').hide();

Or you can slide it up with:

$('...').slideUp();

to get a nice sliding up animation.

On a side note, you can do this to multiple elements at once, in your case:

$('[id$=txtbxthis], [id$=txtbxthat], [id$=txtbxtheother]').slideUp();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!