Home >Web Front-end >JS Tutorial >JavaScript quickly sets the initial selected option according to the value of option_form effects

JavaScript quickly sets the initial selected option according to the value of option_form effects

WBOY
WBOYOriginal
2016-05-16 19:10:181132browse

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



written by misshjn








<script> <BR><!-- <BR>function test(value){ <BR> var opt = document.getElementById("ss").innerHTML.toString(); <BR> var re = new RegExp(value,"g"); <BR> opt = opt.replace(/<OPTION|<\/OPTION>| selected|value/g,"").match(/=.*?>/g).toString().replace(/=|>/g,"").replace(re,"┢").replace(/[^,┢]/g,"").indexOf("┢"); <BR> document.getElementById("ss").getElementsByTagName("option")[opt].selected = true; <BR>} <BR>function randomselect(){ <BR> document.getElementById("ss").getElementsByTagName("option")[Math.floor(Math.random()*document.getElementById("ss").getElementsByTagName("option").length)].selected = true; <BR>} <BR>//--> <BR></script> <script> <BR><!-- <BR>var opts; <BR>for (i=1900; i<2008; i++){ <BR> opts +="<option value='"+i+"'>第 "+i+" 年"; <BR>} <BR>document.write("<select id='ss'>"+opts+""); <BR>//--> <BR></script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn