jquery-模拟打开select

罗星洲
2023-12-01

<select id="ts" size="1">
    <option value="1">1</option>
    <option value="2">Lorem ipsum dolor s.</option>
    <option value="3">3</option>
    <option value="3">4</option>
    <option value="3">5</option>
</select>

<input type="button" id="click" value="Click"/>

    $(function(){
	$("#click").on('click', function(){
		   var s = $("#ts").attr('size')==1?5:1
		   $("#ts").attr('size', s);
	});
	   $("#ts option").on({
		   click: function() {
			   $("#ts").attr('size', 1);
		   },
		   mouseenter: function() {
			   $(this).css({background: '#498BFC', color: '#fff'});
		   },
		   mouseleave: function() {
			   $(this).css({background: '#fff', color: '#000'});
		   }
	   });
     });



来自: http://jsfiddle.net/g3Ta3/4/

 类似资料: