(function(){
jQuery.fn.elRandomSelect = function( min , max ){
var selector = 'option';
selector += ( min || 0 ) > 0 ? ':gt(' + ( parseInt( min )-1 )+ ')' : '';
if ( typeof max !== 'undefined' ) {
max = parseInt( max );
selector += ':lt('+ max +')';
}
return this.each(function(){
if ( ! $( this ).is( 'select' ) )
return;
var options = $( selector , this ),
rand = Math.floor( options.size() * ( Math.random() % 1 ) );
options
.removeAttr( 'selected' )
.eq( rand )
.attr( 'selected' , 'selected' );
});
};
})();
$( 'select' ).elRandomSelect();
เคยเขียน jQuery ปลั๊กอิน กากๆ เอามาไว้ในใช้ใน iMacros
แต่ถ้าไม่รู้วิธีเอา jQuery มาใช้ใน iMacros คงคุยกันอีกยาว