我试过了。。工作很好,但你的代码更好,更短
<script type="text/javascript">
$(document).ready(function(){
$("#gallery2 img").each( function() {
var posneg = Math.floor( (Math.random() * 2) );
if (posneg == 0) {posneg=-1} else {posneg=1};
var angle = Math.floor( (Math.random() * 5) * posneg );
$(this).css( 'transform', 'rotate(' + angle + 'deg)' );
$(this).css( '-moz-transform', 'rotate(' + angle + 'deg)' );
$(this).css( '-webkit-transform', 'rotate(' + angle + 'deg)' );
$(this).css( '-o-transform', 'rotate(' + angle + 'deg)' );
alert(angle);
});
});
</script>