我们知道window onload或者body的onload方法,都是在页面加载完后才执行的,也就像是组最后执行的js方法,那么如何让我需要的js function 最后执行呢,或者定义其执行顺序,那就需要用到,setTimeout方法了
使用方法demo:
  <script>
    function getaddress(){ // set address from DB
      var province_db = document.getElementById('province_value').value;
      var city_db = document.getElementById('city_value').value;
      with(document.userinfo.province) {var loca2 = province_db; }
      for(i = 0;i < where.length;i ++) {
        if (where[i].loca == loca2) {
          loca3 = (where[i].locacity).split("|");
          for(j = 1;j < loca3.length;j++)
          { with(document.userinfo.city){ length = loca3.length; options[j].text = loca3[j]; options[j].value = loca3[j];}}
          break;
        }
      }
      var length = document.userinfo.province.length;
      var length_city = document.userinfo.city.length;
      for(i = 0; i < length;i++){
        if(document.getElementById('province').options[i].value == province_db){
          document.getElementById('province').selectedIndex = i;
        }
      }
      for(i = 0 ; i< length_city;i++){
        if(document.getElementById('city').options[i].value == city_db){
          document.getElementById('city').selectedIndex = i;
        }
      }
    }
    setTimeout("getaddress()", 1000);
</script>
setTimeout(函数,时间) 意为延迟执行的时间,只执行一次
ref:
http://blog.csdn.net/lne818/archive/2008/03/03/2143753.aspx
	posted on 2009-06-16 18:55 
fl1429 阅读(286) 
评论(0)  编辑  收藏  所属分类: 
Ajax