用户编辑页面,点击保存没反应,页面调试也没有js报错,请老师指点一下

来源:7-5 编辑和修改登录人信息

李昂八世

2019-02-20

edit.js

;
var user_edit_ops = {
    init:function(){
        this.eventBind();
    },
    eventBind:function(){
        $(".user_edit_wrap.save").click(function(){
            var btn_target = $(this);
            if( btn_target.hasClass("disabled") ){
                common_ops.alert("正在处理!!请不要重复提交~~");
                return;
            }

            var nickname_target = $(".user_edit_wrap input[name=nickname]");
            var nickname = nickname_target.val();

            var email_target = $(".user_edit_wrap input[name=email]");
            var email = email_target.val();

            if( !nickname || nickname.length < 2 ){
                common_ops.tip("请输入符合规范的姓名~~",nickname_target);
                return false;
            }

            if(!email || email.length < 2){
                common_ops.tip("请输入符合规范的邮箱~~",nickname_target);
                return false;
            }

            btn_target.addClass("disabled");

            var data = {
                nickname: nickname,
                email: email
            };

            $.ajax({
                url:common_ops.buildUrl("/user/edit"),
                type:'POST',
                data:data,
                dataType:'json',
                success:function(res){
                    btn_target.removeClass("disabled");
                    var callback = null;
                    if(res.code == 200){
                        callback = function(){
                            window.location.href = window.location.href;
                        }
                    }
                    common_ops.alert(res.msg,callback);
                }
            });


        });
    }
};

$(document).ready( function(){
    user_edit_ops.init();
} );

edit.html

{% extends "common/layout_main.html" %}
{% block content %}
<div class="row  border-bottom">
    <div class="col-lg-12">
        <div class="tab_title">
            <ul class="nav nav-pills">
                <li class="current">
                    <a href="{{ buildUrl('/user/edit') }}">信息编辑</a>
                </li>
                <li>
                    <a href="{{ buildUrl('/user/edit') }}">修改密码</a>
                </li>
            </ul>
        </div>
    </div>
</div>
<div class="row m-t  user_edit_wrap">
    <div class="col-lg-12">
        <h2 class="text-center">账号信息编辑</h2>
        <div class="form-horizontal m-t m-b">
            <div class="form-group">
                <label class="col-lg-2 control-label">手机:</label>
                <div class="col-lg-10">
                    <input type="text" name="mobile" class="form-control" placeholder="请输入手机~~" readonly=""
                           value="{{ current_user.mobile }}">
                </div>
            </div>
            <div class="hr-line-dashed"></div>

            <div class="form-group">
                <label class="col-lg-2 control-label">姓名:</label>
                <div class="col-lg-10">
                    <input type="text" name="nickname" class="form-control" placeholder="请输入姓名~~" value="{{ current_user.nickname }}">
                </div>
            </div>
            <div class="hr-line-dashed"></div>

            <div class="form-group">
                <label class="col-lg-2 control-label">邮箱:</label>
                <div class="col-lg-10">
                    <input type="text" name="email" class="form-control" placeholder="请输入邮箱~~" value="{{ current_user.email }}">
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <div class="col-lg-4 col-lg-offset-2">
                    <button class="btn btn-w-m btn-outline btn-primary save">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block js %}
<script src="{{ buildStaticUrl('/js/user/edit.js') }}"></script>
{% endblock %}

写回答

1回答

编程浪子

2019-02-20

你好:

$(".user_edit_wrap.save").click   这个地方是不是写错了 应该是 $(".user_edit_wrap  .save").

0
2
DF49
老师,我按照你的提示操作后还是点击保存没有反应是怎么回事
2020-04-23
共2条回复

Python Flask构建微信小程序订餐系统(可用于毕设)

微信小程序 + Python Flask 打造订餐系统全栈应用,可用于毕设。

1709 学习 · 1889 问题

查看课程