Random selection in Combobox?
I need to know how could do to make a combobox to display a different selection each time you load the page, n开发者_如何学JAVAot create them, if not to show the options that exist, each time you load the page shows a different selection....like randomize the default selected option...thank's in advance
This should do the trick:
var select = document.getElementById('foo');
var items = select.getElementsByTagName('option');
var index = Math.floor(Math.random() * items.length);
select.selectedIndex = index;
http://jsfiddle.net/lakario/dHLax/
精彩评论