- <form role="form" action="/save_element/" method="post" id="obj_form" onsubmit="return select_disable()">
- {% csrf_token %}
- <select class="form-control" name="obj_find_type" id="{{ elements.type_select_id }}" style="border: none;outline:medium;width: 250px;" disabled>
- {% for find_type in find_type_list %}
- {% if elements.type == find_type %}
- <option value = {{ find_type }} selected="selected" >{{ find_type }}</option>
- {% else %}
- <option value = {{ find_type }}>{{ find_type }}</option>
- {% endif %}
- {% endfor %}
- </select>
- <div class="well well-sm" style="text-align:center">
- <button id="do_save" type="submit" class="btn btn-primary btn-flat m-b-10 m-l-5">保存</button>
- </div>
- </form>
JS代码如下:
- <script type="text/javascript">
- function select_disable(){
- //先获取所有的select标签对象
- var select_name = document.getElementsByTagName("select");
- //逐个遍历select
- for(var i=0; i<select_name.length; i++){
- //select_name是一个数组
- //获取select的id值
- var select_id = select_name[i].id;
- //使用id值操作标签属性disabled
- $("#" + select_id).attr("disabled",false);
- }
- }
- </script>