Select中的option都没有设置selected,在select控件中添加一自定义属性“default_select”
default_select值是从后台传递过来的,通过JS在onload事件中调用方法
function setSelect() {
  var s = document.all.tags("select");
  for(var i=0;i<s.length;i++) {
    s[i].selectedIndex = s[i].default_select;
  }
}
来设置select控件的默认值但是如果点击表单中的
<input type="reset" name="cancel" id="cancel" value="取消编辑" />
按钮的话,则select中的值都变成第一个option的值了...有什么办法可以避免这种情况吗?

解决方案 »

  1.   

    <input type="reset" name="cancel" id="cancel" value="取消编辑" 
    onclick="resetFun();return false;"/>
      

  2.   

    in this function (resetFun) reset objects what you want to reset
    return false -->
      

  3.   

    <input type="reset" name="cancel" id="cancel" value="取消编辑" />
    不要用 reset,直接用 button
    <input type="button" name="cancel" id="cancel" value="取消编辑" />L@_@K<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
     </head> <body>
     <form method="post" action="">
    <input type="text" />
    <select default_select="1">
    <option value="">请选择</option>
    <option value="">1</option>
    <option value="">2</option>
    <option value="">3</option>
    </select>
    <input type="button" name="cancel" id="cancel" value="取消编辑" />
     </form>
      <script type="text/javascript">
      <!--
    function setSelect() {
      var s = document.all.tags("select");
      for(var i=0;i<s.length;i++) {
        s[i].selectedIndex = s[i].default_select;
      }
    }setSelect();document.getElementById("cancel").onclick = function() {
    this.form.reset();
    setSelect();
    };  //-->
      </script>
     </body>
    </html>
    Web 开发常用手册JScript语言参考.rar
    http://download.csdn.net/source/308916DHTML参考手册.rar
    http://download.csdn.net/source/308913样式表中文手册.chm
    http://download.csdn.net/source/304124