1. 程式人生 > >form serilize() 返回值中的內容替換

form serilize() 返回值中的內容替換

function replaceFormContent(data,target,solution) {
    var data2 = data.split("&"+target)
    var data3 = data2[1].substr(0,data2[1].indexOf("&"));
    var data4 = data2[1].substr(data2[1].indexOf("&"),data2[1].length);
    var content = data3;
    if (content != "=") {
        content ="="+ solution(content.substr(1,content.length))
    }
    data = data2[0] + "&"+target +content+data4
    return data;
}

data = replaceFormContent(data,"password",function (content) { return $.md5(content) })