window.onload=initForm;
var a=document.getElementById("newLocation");
function initForm()
{
a.selectedIndex=0;//让页面返回时默认选择为第一个option
a.onchange=goPage;
}function goPage()
{
var a=document.getElementById("newLocation");
var b=a.options[a.selectedIndex].value;
if(b!="")
{
window.location=b;
}
}
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>select navigation</title>
<script src="js/select navigation.js"></script>
</head>
<body>
<form action="">
<select id="newLocation">
<option>友情链接</option><!--有了document.getElementById("newLocation").selectedIndex=0;-->
<option value="http://www.baidu.com">百度</option>
<option value="http://www.google.hk">谷歌</option>
<option value="http://www.qq.com">腾讯</option>
<option value="http://www.sohu.com">搜狐</option>
</select>
</form>
</body>
</html>

解决方案 »

  1.   

    //利用循环创建随机数在卡片上
    window.onload=all;var usedNum=new Array(76);//uesdNum[1-75],所以为76,注意此时未给数组赋值
    var newArray=new Array(0,1,2,3,4,0,1,2,3,4,0,1,3,4,0,1,2,3,4,0,1,2,3,4)function all()
    {
    newCard();
    document.getElementById("reload").onclick=anotherCard;//这样只在本页面下活动,不会占用服务器资源
    }
    //页面加载时出现的一组
    function newCard()
    {
    for(var i=0;i<24;i++)
    {
    var num;
    //让第一列为1-15,第二列16-30,以此类推,且随机的数字不会出现重复
    do
    {
    num=Math.floor(Math.random()*15)+1+(newArray[i]*15);
    }
    while(usedNum[num]);//当数已经存在,回到do再随机一个数直到该数未出现过
    usedNum[num]=true;//找到新数离开循环后将usedNum[num]设置为true代表该数存在了
    document.getElementById("square"+i).innerHTML=num;//再将num写到卡片上
    }
    }
    //另一组合上一组不重复的数
    function anotherCard()
    {
    for(var i=1;i<usedNum.length;i++)
    {
    usedNum[i]=false;//重置数组所有元素为未存在状态,这样可以永远刷新下去
    }
    newCard();//继续刷新一次
    }这个全局变量就可以啊
      

  2.   

    var a=document.getElementById("newLocation");
    这句话是在页面加载的时候就执行了,但是这个时候页面还为加载完毕,还没有newLocation这个id的元素,所以,如果你想得到这个值,得在页面加载完毕后,给a赋值
      

  3.   

    window.onload=initForm;
    var a;
    function initForm()
    {
    a=document.getElementById("newLocation");
    a.selectedIndex=0;//让页面返回时默认选择为第一个option
    a.onchange=goPage;
    }