Combobox中的随机选择? [英] Random selection in Combobox?
本文介绍了Combobox中的随机选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道如何在每次加载页面时使组合框显示不同的选择,而不是创建它们,如果不显示存在的选项,则每次加载页面时都会显示不同的选择。 ... ...像随机化默认选择的选项...提前感谢
解决方案
这应该做的诀窍:
var select = document.getElementById('foo');
var items = select.getElementsByTagName('option');
var index = Math.floor(Math.random()* items.length);
select.selectedIndex = index;
$ nofollow> http://jsfiddle.net/lakario/dHLax/
I need to know how could do to make a combobox to display a different selection each time you load the page, not 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/
这篇关于Combobox中的随机选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文