码迷,mamicode.com
首页 > 其他好文 > 详细

Add data when form is submitted

时间:2015-05-16 23:20:26      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

Sometimes we want to add extra data to our form and submit them to the server.

We can do this like :

1 var form = document.querySelector(‘form‘);
2     form.onsubmit = function(){
3     var input = document.createElement(‘input‘);
4     input.setAttribute(‘type‘,‘hidden‘);
5         input.setAttribute(‘name‘, elementName);
6         input.setAttribute(‘value‘,elementValue);
7         form.appendChild(input);
8     }

 

Add data when form is submitted

标签:

原文地址:http://www.cnblogs.com/deryck/p/4508818.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!