Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. $('button').on('click', function() {
  2. $('select').trigger('click');
  3. });
  4.  
  5. (function($) {
  6. "use strict";
  7. $.fn.openSelect = function()
  8. {
  9. return this.each(function(idx,domEl) {
  10. if (document.createEvent) {
  11. var event = document.createEvent("MouseEvents");
  12. event.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  13. domEl.dispatchEvent(event);
  14. } else if (element.fireEvent) {
  15. domEl.fireEvent("onmousedown");
  16. }
  17. });
  18. }
  19. }(jQuery));
  20. $('#country').openSelect();
  21.  
  22. <html>
  23. <body>
  24.  
  25. <div class="sorting">
  26. <div class="sort right"><label>
  27. <span>Items per page</span>
  28. <select>
  29. <option value="">Items per page</option>
  30. <option value="10">10</option>
  31. <option value="20">20</option>
  32. <option value="40">40</option>
  33. <option value="60">60</option>
  34. <option value="100">100</option>
  35. <option value="200">200</option>
  36. </select>
  37.  
  38. <span class="pointer"><i class="fa fa-caret-down"></i></span>
  39. </label>
  40. </div>
  41. </div>
  42.  
  43.  
  44. </body>
  45. </html>
  46. <style>
  47. select{
  48. -webkit-appearance:none;
  49. appearance:none;
  50. -moz-appearance:none;
  51. }
  52. .sorting{
  53. padding:5px 10px;
  54. border:1px solid #eee;
  55. clear:both;
  56. background:#FFF;
  57. height:40px;
  58. }
  59. .sorting h4{
  60. padding:4px 0 0;
  61. margin:0;
  62. }
  63. .sort{
  64. position:relative;
  65. padding-left:10px;
  66. float:left;
  67. }
  68. .sort>label{
  69. font-weight:normal !important
  70. }
  71. .sort span.pointer{
  72. height:30px;
  73. width:30px;
  74. border-left:1px solid #ddd;
  75. position:absolute;
  76. right:0;
  77. top:0;
  78. text-align:center;
  79. color:#c49633;
  80. font-size:20px;
  81. z-index:1;
  82. }
  83. .sort span.pointer i{
  84. margin-top:6px;
  85. }
  86. .sorting select{
  87. padding:5px 40px 5px 10px !important;
  88. margin-left:10px;
  89. border:1px solid #eee;
  90. background:none;
  91. height:30px;
  92. position:relative;
  93. z-index:2;
  94. }
  95. </style>
  96.  
  97. $('#dropdown_id_chzn').trigger('mousedown')
  98.  
  99. <select name="foo">
  100. <option value="1">Bar</option>
  101. </select>
  102.  
  103. $('select[name="foo"]').chosen();
  104. $('#foo_chzn').trigger('mousedown');
  105.  
  106. <select id="s">
  107. <option>aaaaa</option>
  108. <option>bbbbb</option>
  109. <option>ccccc</option>
  110. </select>
  111.  
  112. <button>button</button>
  113.  
  114. $("button").click(function () {
  115. var size = $('#s option').size();
  116. if (size != $("#s").prop('size')) {
  117. $("#s").prop('size', size);
  118. } else {
  119. $("#s").prop('size', 1);
  120. }
  121. })
  122.  
  123. $('button').on('click', function() {
  124. $('select').trigger('click');
  125. });
  126.  
  127. $('select').click(function(){
  128. alert($(this).val());
  129. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement