截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

like-select-input.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var set_select = null;
  2. layui.define(["jquery", "form"], function (exports) {
  3. var $ = layui.$;
  4. var ojb = {
  5. init: function () {
  6. $(document).on('input click','.input-select' ,function () {
  7. var url = $(this).attr('data-url');
  8. let that = $(this);
  9. clearTimeout(set_select);
  10. set_select = setTimeout(function () {
  11. $.get(url + '?keyword=' + $(that).val(), function (res) {
  12. var data = res.data;
  13. if (data.length == 0) {
  14. that.next().hide();
  15. return;
  16. }
  17. var dd_exist = (that.parent().find('dl')).length == 0 ? false : true;
  18. var html = dd_exist ? '' : '<dl class="layui-anim layui-anim-upbit select-option">';
  19. for (var i in data) {
  20. html += '<dd>' + data[i] + '</dd>';
  21. }
  22. html += dd_exist ? '' :'</dl>';
  23. if(dd_exist){
  24. that.parent().find('dl').html(html);
  25. }else{
  26. that.after(html);
  27. }
  28. that.next().show();
  29. });
  30. }, 300);
  31. });
  32. $(document).on('blur','.input-select', function () {
  33. let that = this
  34. setTimeout(function () {
  35. $(that).next().hide()
  36. }, 200)
  37. });
  38. $(document).on('click', '.select-option dd', function () {
  39. $(this).parents().prev().val($(this).text());
  40. $(this).parent().remove();
  41. });
  42. }
  43. };
  44. ojb.init();
  45. exports("like-select-input", ojb);
  46. });