multi-select.blade.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <div class="sg-table-multi-select">
  2. <table class="layui-table" id="{{ $id }}" lay-even="true" lay-skin="line" lay-size="sm">
  3. <thead>
  4. <tr>
  5. <th><input class="sg-check-all sg-check-input" type="checkbox" lay-skin="primary"></th>
  6. <th>名称</th>
  7. </tr>
  8. </thead>
  9. <tbody>
  10. @if(count($options) <= 0)
  11. <tr>
  12. <td colspan="2">无数据</td>
  13. </tr>
  14. @else
  15. @foreach($options as $option)
  16. <tr>
  17. <td><input class="sg-check-input sg-data-input" type="checkbox" lay-skin="primary" name="{{ $name }}" value="{{ $option['id'] }}" {{ in_array($option['id'], $selected_ids) ? 'checked' : '' }}></td>
  18. <td>{{ $option['name'] }}</td>
  19. </tr>
  20. @endforeach
  21. @endif
  22. </tbody>
  23. </table>
  24. </div>
  25. <script>
  26. $(function () {
  27. $('#{{ $id }} thead').on('click', function () {
  28. var checked = $('#{{ $id }} .sg-check-all').prop('checked');
  29. if(checked) {
  30. $('#{{ $id }} .sg-check-input').prop('checked', true);
  31. $('#{{ $id }} .layui-form-checkbox').addClass('layui-form-checked');
  32. } else {
  33. $('#{{ $id }} .sg-check-input').prop('checked', false);
  34. $('#{{ $id }} .layui-form-checkbox').removeClass('layui-form-checked');
  35. }
  36. });
  37. })
  38. </script>