方便的post提交

页面里有多行记录,每行记录后面对应着编辑操作,点击操作链接或按钮要跳到另一个页面,通常需要传递id,但有的时候除了id还要传名字等,这样有不妥的地方:

1,传递的参数都在地址栏里,别人都看见了

2,有中文,有的时候地址栏传中文会出错的

 

希望post提交,如果对每一行都做个表单,感觉不太好,所以写了一个JavaScript类,方便post提交

  1. function TheForm(url,data){
  2.     var _theForm = document.body.appendChild(document.createElement('form'));
  3.     _theForm.action = url;
  4.     for(var property in data){
  5.         var _input = document.createElement('input');
  6.         _input.type = 'hidden'//type属性要写在 input被添加到页面上之前
  7.         _input.name = property;
  8.         _input.value = data[property];
  9.         _theForm.appendChild(_input); //input 添加到页面
  10.     }
  11.     this._theForm = _theForm;
  12.     if(!TheForm._initialized){ //初始化类的方法
  13.         TheForm.prototype.post = function(){
  14.             this._theForm.method = 'post';
  15.             this._theForm.submit();
  16.         }
  17.         TheForm.prototype.get = function(){
  18.             this._theForm.method = 'get';
  19.             this._theForm.submit();
  20.         }
  21.         TheForm._initialized = true;
  22.     }
  23. }




    调用示例:

    new TheForm('quanxian.jsp',{id:'<%=dataMap.get("Account")%>'}).post();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值