显示/隐藏带有匹配复选框的内容

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了显示/隐藏带有匹配复选框的内容相关的知识,希望对你有一定的参考价值。

This function follows the following naming conventions: Give your checkboxes ID tags of "[contenttitle]trigger", where [contenttitle] is whatever you like. Then, give your hide-able content classes that match, without the "trigger". This function will look at the checkbox ID and checked state, and then show/hide the content with those classes accordingly.

So for example, you have a checkbox with the ID "content4trigger", and two divs with the class "content4". This will show and hide the divs based on the id of the checkbox.
  1. function checkToggler(element) {
  2. var actionItem = $(element).attr("id");
  3. actionItem = actionItem.substring(0, actionItem.indexOf("trigger"));
  4.  
  5. if( $(element).is(':checked') ) {
  6. $("."+actionItem).show();
  7. } else {
  8. $("."+actionItem).hide();
  9. }
  10. }
  11.  
  12. // You can call the function like this:
  13.  
  14. $(".selectionBox input").change(function(){
  15. checkToggler( $(this) );
  16. });

以上是关于显示/隐藏带有匹配复选框的内容的主要内容,如果未能解决你的问题,请参考以下文章

Sphinx、reStructuredText 显示/隐藏代码片段

如何在Angular2中显示和隐藏带有复选框元素的div?

在片段替换上显示/隐藏 Android 软键盘

PyQt-QtableView 标头。如何添加右上角的小按钮以隐藏/显示带有选中/未选中复选框的列?

当涉及另一个复选框时,使用带有“checkbox.checked === true”的 if/then 命令隐藏/显示元素时出现问题

带有复选框和自定义适配器的 ListView,片段无法正常工作