JavaScript option's value value quickly sets the initial selected options _ form effects

Source: Internet
Author: User
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>written by misshjn</title>
<script language= "JavaScript" >
<!--
function test (value) {
var opt = document.getElementById ("ss"). Innerhtml.tostring ();
var re = new RegExp (value, "G");
opt = Opt.replace (/<option|<\/option>| selected|value/g, ""). Match (/=.*?>/g). toString (). Replace (/=| >/g, ""). Replace (Re, "┢"). Replace (/[^,┢]/g, ""). IndexOf ("┢");
document.getElementById ("ss"). getElementsByTagName ("option") [opt].selected = true;
}
function Randomselect () {
document.getElementById ("ss"). getElementsByTagName ("option") [Math.floor (Math.random () *document.getelementbyid ( "SS"). getElementsByTagName ("option"). length].selected = true;
}
-->
</SCRIPT>
<body>
<!--
<select id= "ss" >
<option value= "1998" >1998 year </option>
<option value= "1999" >1999 year </option>
<option value= ">2000" year </option>
<option value= "2001" >2001 year </option>
<option value= "2002" >2002 year </option>
<option value= "2003" >2003 year </option>
<option value= ">2004" year </option>
<option value= ">2005 Year" </option>
</select>
-->
<script language= "JavaScript" >
<!--
var opts;
For (i=1900 i<2008; i++) {
opts + = "<option value= '" +i+ "' >" +i+ "Year </option>";
}
document.write ("<select id= ' ss ' >" +opts+ "</select>");
-->
</SCRIPT>
<input type= "button" value= "select value=2001 option" onclick= "Test (' 2001 ')" >
<input type= "button" value= "randomly selected" onclick= "Randomselect ()" >
</body>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.