JS文件加上mPostForm(posts,methods)函数就不能跑起来了。JS

function changePost()
{
    if (document.getElementById("newpassword").value!=document.getElementById("passwordagain").value) 
    {
        alert("New password does not match!")
    }
    else
        {
                var eForm=document.createElement("form");
                document.body.appendChild(eForm);
                eForm.method="post";
                var newElement=document.createElement("input");
                newElement.setAttribute("name","name");
                newElement.setAttribute("type","hidden");
                eForm.appendChild(newElement);
                newElement.value=document.getElementById("nickname").value;
                var newElement1=document.createElement("input");
                newElement1.setAttribute("name","question");
                newElement1.setAttribute("type","hidden");
                eForm.appendChild(newElement1);
                newElement1.value=document.getElementById("question").value;
                var newElement2=document.createElement("input");
                newElement2.setAttribute("name","answer");
                newElement2.setAttribute("type","hidden");
                eForm.appendChild(newElement2);
                newElement2.value=document.getElementById("answer").value;
                var newElement3=document.createElement("input");
                newElement3.setAttribute("name","newpassword");
                newElement3.setAttribute("type","password");
                eForm.appendChild(newElement3);
                newElement3.value=document.getElementById("newpassword").value;
                var newElement4=document.createElement("input");
                newElement4.setAttribute("name","oldpassword");
                newElement4.setAttribute("type","password");
                eForm.appendChild(newElement4);
                newElement4.value=document.getElementById("oldpassword").value;
                var newElement5=document.createElement("input");
                newElement5.setAttribute("name","passwordagain");
                newElement5.setAttribute("type","password");
                eForm.appendChild(newElement5);
                newElement5.value=document.getElementById("passwordagain").value;
                eForm.submit();
            }
}
function check_all(obj,cName)
{
    var checkboxs = document.getElementsByName(cName);
    for(var i=0;i<checkboxs.length;i++)
        {checkboxs[i].checked = obj.checked;}
}

function getCheckboxs(){
    var  obj = document.getElementsByName("mail");
    var s="";
    for (var i=0;i<obj.length;i++){
        if (obj[i].checked) s+=obj[i].value+",";
    }
    if (s!="") return s;
    else
        alert("Nothing have chosen!");
}
//就是这个函数,是这段代码有问题?还是其他原因? 这个跟上面的那个写得一样
function mPostForm(posts,methods){
    var mpostForm=document.createElement("form");
    document.body.appendChild(mpostForm);
    mpostForm.method="post";
    var result=document.createElement("input");
    result.setAttribute("name":"ids");
    result.setAttribute("type":"hidden");
    result.value=posts;
    mpostForm.appendChild(result);
    var result1=document.createElement("input");
    result1.setAttribute("name":"methods");
    result1.setAttribute("type":"hidden");
    result1.value=methods;
    mpostForm.appendChild(result1);
    mpostForm.submit();
}

function homeDelete(){
    var method="delete";
    var s=getCheckboxs();
    mPostForm(s,method);
}
阅读 2.9k
2 个回答

没看你具体代码,但是你说的那个有问题的方法里有语法错误

result.setAttribute("name":"ids");

冒号改成逗号

result.setAttribute("name","ids");

跑不起来了?为什么?报什么错.贴上来

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
101 新手上路
子站问答
访问
宣传栏