开发者

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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜