标签:
1 <select> 2 <option>aaaaa</option> 3 <option>bbbbb</option> 4 <option>ccccc</option> 5 </select> 6 <button>button</button> 7 <script> 8 $.fn.openSelect = function() { 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 $(‘button‘).on(‘click‘, function() { 20 $(‘select‘).openSelect(); 21 }); 22 </script>
该处用到了XML的【XML】document.createEvent的使用方法
【jquery、XML】jquery通过按钮使打开select
标签:
原文地址:http://www.cnblogs.com/luanhewei/p/5798993.html