大镇 阅读(83) 评论(0)
html代码

  1. <form role="form" action="/save_element/" method="post" id="obj_form" onsubmit="return select_disable()">
  2. {% csrf_token %}
  3.     <select class="form-control" name="obj_find_type" id="{{ elements.type_select_id }}" style="border: none;outline:medium;width: 250px;" disabled>
  4.         {% for find_type in find_type_list %}
  5.              {% if elements.type == find_type %}
  6.                 <option value = {{ find_type }} selected="selected" >{{ find_type }}</option>
  7.              {% else %}
  8.                 <option value = {{ find_type }}>{{ find_type }}</option>
  9.              {% endif %}
  10.         {% endfor %}
  11.     </select>
  12.     <div class="well well-sm" style="text-align:center">
  13.         <button id="do_save" type="submit" class="btn btn-primary btn-flat m-b-10 m-l-5">保存</button>
  14.     </div>
  15. </form>
想要把form里面的所有select 标签的disabled 都去掉。
JS代码如下:

  1. <script type="text/javascript">

  2. function select_disable(){
  3.     //先获取所有的select标签对象
  4.     var select_name = document.getElementsByTagName("select");
  5.     //逐个遍历select
  6.     for(var i=0; i<select_name.length; i++){
  7.         //select_name是一个数组
  8.         //获取select的id值
  9.         var select_id = select_name[i].id;
  10.         //使用id值操作标签属性disabled
  11.         $("#" + select_id).attr("disabled",false);
  12.     }
  13. }

  14. </script>