Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有 3 个带有 id control_1、control_2、的控件control_3。
control_1
control_2
control_3
我想隐藏这些控件。
目前我正在使用这个:
$('#control_1').hide(); $('#control_2').hide(); $('#control_3').hide();
有没有更好的方法来做到这一点?
我可以做类似的事情$('control_*').hide();吗?
$('control_*').hide();
有没有办法找到以特定名称开头的控件?
为了完整起见,您可以使用带有属性过滤器的开头:
$('[id^="control_"]').hide();
也就是说,对于大多数目的,最好采用其他建议之一。
相反,您可以为控件设置相同的类并像这样隐藏它们:
$('.controlClass').hide();
为什么不用类似的类替换 ID .controls?然后只需使用:
.controls
$(".controls").hide();
你可以使用:
$('#control_1,#control_2,#control3').hide();
或使用属性StartsWith