用下面的函数可以获取:
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i")
var r = window.location.search.substr(1).match(reg)
if (r != null) return decodeURI(r[2])
return null
}
如获取user,执行getUrlParam("user")就可以了
表单是用form来填写,在提交前可以获取表单里面的数据。我这里用jquery实现。
<html><body>
<form method='post' action=''>
<label for='inputText'>inputText</label>
<input type='text' id='inputText'/>
<br/>
<label for='checkBox1'>checkBox1</label>
<input type='checkbox' id='checkBox1'/>
<br/>
<label for='checkBox2'>checkBox2</label>
<input type='checkbox' id='checkBox2'/>
<!--其他你想填写的表单选项-->
<input type='button' value='提交表单' id='submitBtn'/>
</form>
<script>
$(document).ready(function()
{
$('#submitBtn').click(function(e)
{
/*一系列根据自己的意图判断输入框是否已输入内容并决定是否往下执行*/
//获取表单的系列化数据。这会生成一个A=valueA&B=valueB这种形式的字符串。
var formData = $('form').serialize()
$.post('目标地址',formData,成功/失败回调函数)
e.preventDefault()
})
})
</script>
</body>
</html>
直接用js里的getElementsByName就可以获取所以name值相同的元素。但获取出来的并不是数组,而是类数组的元素集合。所以还需要一步变换,下面是简单代码:<body> <input type="text" name="111" /> <input type="text" name="111" /> <input type="text" name="111" /> <input type="text" name="111" /> <input type="text" name="111" /> <input type="text" name="111" /> <input type="text" name="111" /> <input type="text" name="111" /> </body> <script> var oInp = document.getElementsByName('111') var aInp = [] for(var i=0i<oInp.lengthi++){aInp.push(oInp[i]) }</script> //这样aInp这个数组里存储的就是所以元素name为111的数组。