页面里有多行记录,每行记录后面对应着编辑操作,点击操作链接或按钮要跳到另一个页面,通常需要传递id,但有的时候除了id还要传名字等,这样有不妥的地方:
1,传递的参数都在地址栏里,别人都看见了
2,有中文,有的时候地址栏传中文会出错的
希望post提交,如果对每一行都做个表单,感觉不太好,所以写了一个JavaScript类,方便post提交
- function TheForm(url,data){
- var _theForm = document.body.appendChild(document.createElement('form'));
- _theForm.action = url;
- for(var property in data){
- var _input = document.createElement('input');
- _input.type = 'hidden'; //type属性要写在 input被添加到页面上之前
- _input.name = property;
- _input.value = data[property];
- _theForm.appendChild(_input); //input 添加到页面
- }
- this._theForm = _theForm;
- if(!TheForm._initialized){ //初始化类的方法
- TheForm.prototype.post = function(){
- this._theForm.method = 'post';
- this._theForm.submit();
- }
- TheForm.prototype.get = function(){
- this._theForm.method = 'get';
- this._theForm.submit();
- }
- TheForm._initialized = true;
- }
- }
调用示例:
new TheForm('quanxian.jsp',{id:'<%=dataMap.get("Account")%>'}).post();