基于用户选择显示/隐藏内容 jQuery serialexpand

  • 源码大小:8.39KB
  • 所需积分:1积分
  • 源码编号:19JP-3661
  • 浏览次数:706次
  • 最后更新:2023年07月08日
  • 所属栏目:其他
本站默认解压密码:19jp.com 或 19jp_com

简介

serialexpand是一个轻量级的jQuery插件,用于条件可见性,可以根据复选框、单选按钮和下拉选择平滑地显示和隐藏内容。

如何使用它:

1.加载最新的jquery JavaScript库后,添加JavaScript jquery.serializexpand.js。

  1. <script src="/path/to/cdn/jquery.min.js"></script>
  2. <script src="/path/to/dist/jquery.serialexpand.js"></script>

2.初始化插件,我们就可以开始了。

  1. $(document).ready(function(){
  2. $.serialexpand({
  3. selector: '[data-serialexpand]'
  4. });
  5. });

3.启用单选按钮以在DIV块之间切换。

  1. <!-- Radio Buttons -->
  2. <input type="radio" data-serialexpand="div-1">
  3. <input type="radio" data-serialexpand="div-2">
  4.  
  5. <!-- DIV Blocks To Show/Hide -->
  6. <div data-serialexpand-target="div-1">
  7. For Radio Button 1
  8. </div>
  9. <div data-serialexpand-target="div-2">
  10. For Radio Button 2
  11. </div>

4.启用复选框以显示您指定的内容。

  1. <!-- Checkboxes -->
  2. <input type="checkbox">
  3. <input type="checkbox">
  4. <input type="checkbox" data-serialexpand="div-3">
  5.  
  6. <!-- DIV Block To Show/Hide -->
  7. <div data-serialexpand-target="div-3">
  8. For Checkbox 3
  9. </div>

5.根据用户在下拉选择中选择的选项在DIV块之间切换。

  1. <!-- Dropdown Select -->
  2. <select>
  3. <option data-serialexpand="div-4">Option 1</option>
  4. <option data-serialexpand="div-5">Option 2</option>
  5. <option>Option 3</option>
  6. </select>
  7.  
  8. <!-- DIV Block To Show/Hide -->
  9. <div data-serialexpand-target="div-4">
  10. For Option 1
  11. </div>
  12. <div data-serialexpand-target="div-5">
  13. For Option 2
  14. </div>

6.指定在内容之间切换时要使用的动画。看见https://api.jquery.com/category/effects/了解更多详细信息。

  1. $(document).ready(function(){
  2. $.serialexpand({
  3. selector: '[data-serialexpand]',
  4. fxIn: 'slideDown',
  5. fxOut: 'slideUp',
  6. });
  7. });

预览截图