今天主要是四个问题:
1.表单页面元素的获取;
2.按钮的值的获取;
3.按钮的值以变量提交;
4.表单的提交;
var radiovar = document.getElementsByName("sex"); if (radiovar[0].value=== node.childNodes[2].innerHTML ) { radiovar[0].checked="checked"; } if (radiovar[1].value===node.childNodes[2].innerHTML ) { radiovar[1].checked="checked"; }
3.然后将表单上的值取出来,又传给后端。
var scct =‘‘; if(node.childNodes[2].childNodes[0].childNodes[0].checked===true){ scct=‘M‘; } else if(node.childNodes[2].childNodes[0].childNodes[0].checked===false){ scct=‘F‘; }
4.表单的提交,开始用的是
this.location = "../requests/myPhotographers/dropPhotographer.php?account=" + act + "";
的方法,发现判断它返回值的函数不能使用,是因为此方法会使页面跳转,所以使用ajax提交表单的方法提交
if (fcStart === 0) { $(‘#usemf‘).on(‘submit‘, function (e) { // document.getElementById("aaa").innerHTML = ‘aaaaa‘;//when form submit // alert(‘submit!‘); e.preventDefault(); //prevent it being sent var details = $(‘#usemf‘).serialize(); //serialize from data }); var uem = new XMLHttpRequest(); uem.onload = function() { if (uem.status === 200) { var newLoad = ""; // var returnDataP = "error:Authentication Failed For RDS maybe username or password is incorrect"; // var returnDataA = "error:Access denied for user ‘gty‘@‘localhost‘ (using password: YES)"; // var returnDataN = "error:user not exist"; //定义匹配信息 var patt1=new RegExp("error:You do not have permission to modify the photographer!"); var patt2=new RegExp("The modification is successful!"); if (patt1.test(uem.responseText)){ //如果返回数据为error。。,则弹出没有权限 newLoad = "<div class=\"alert alert-block\" > <button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button> <h2>sorry!</h2> <h4>您没有修改权限!</h4></div>"; setTimeout(dute,500) } if (patt2.test(uem.responseText)){ //如果返回数据包含successful,则弹出修改成功 newLoad = "<div class=\"alert alert-success\" > <button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button> <h2>congratulation!</h2> <h4>修改摄影师成功!</h4></div>"; setTimeout(dute,500) } } document.getElementById("usemf").innerHTML = newLoad; }; uem.open("get", "../requests/myPhotographers/modifyPhotographer2.php?account="+ncct+"&name="+acct+"&sex="+scct+ "" +"&phoneNumber="+pcct+"&email="+ecct+"", true); uem.send(); }
此方法不仅可以阻止页面跳转,还可以将数据以get的方式发送。
原文:http://www.cnblogs.com/shuxiao3/p/7231686.html