BBS little doubt point projects and solutions -C articles (has-error, ajax callback function of the dictionary set ... (to be continued))

11. js input box for has-error-add

This is a fixed wording, said in the input box error occurs, a red box will be reported, and when the cursor focus input box, will restore the original color, I write today to underline the middle of the horizontal line

$.each(data.msg,function (index, obj) {
            var targetId = '#id_' + index;                            $(targetId).next().text(obj[0]).parent().addClass('has-error')
                    })





$('input').focus(function () {
        $(this).next().text('').parent().removeClass('has-error')
    })

'''
上面:

这个是放在ajax的回调函数里的,用于判断前端用户注册时输入是否正确,上面的代码主要是错误的逻辑。因为通过前端检查,发现ajax的回调函数id名称是id+标签name,所以就进行拼接。
有错误(错误信息就是text里面的obj[0], 这里js可以点各种方法,点一次执行一次,而不是点到底执行一次)就报红(addClass('has-error'))



下面:

这个是,光标移入,错误信息为空,且框变正常(即把has-error类移除)
'''



12. ajax callback request to have a rear end of the function, a dictionary is provided for herein generally spread front end

'''一般的格式是
back_dic = {'code': 1000, 'msg': ''}
里面还可以加url键值,然后用jsonresponse包裹传到前端,前段可以直接用
'''

Back-end code detailed analysis, see the github (post-fill)

Guess you like

Origin www.cnblogs.com/michealjy/p/11784582.html