Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用多个同名元素提交表单GET会导致长查询字符串_Jquery_Forms_Get - Fatal编程技术网

Jquery 使用多个同名元素提交表单GET会导致长查询字符串

Jquery 使用多个同名元素提交表单GET会导致长查询字符串,jquery,forms,get,Jquery,Forms,Get,我有一个表单[method=get],它有许多复选框,所有复选框都有相同的名称 提交表单时,url看起来像 ?MyCB=0&MyCb=4&MyCB=10 我希望GET请求在浏览器中显示为(有效且有效) 是否可以在表单上设置属性来执行此操作 最后一种方法是使用jquery截取GET(这就是为什么我标记为这样,以防有任何帮助函数存在)。您甚至不能使用$\u GET和jquery处理整个表单,然后将window.location设置为数组 不幸的是,您不能添加允许表单将多个$\u G

我有一个
表单[method=get]
,它有许多复选框,所有复选框都有相同的名称

提交表单时,url看起来像

?MyCB=0&MyCb=4&MyCB=10
我希望GET请求在浏览器中显示为(有效且有效)

是否可以在表单上设置属性来执行此操作


最后一种方法是使用jquery截取GET(这就是为什么我标记为这样,以防有任何帮助函数存在)。

您甚至不能使用$\u GET和jquery处理整个表单,然后将window.location设置为数组


不幸的是,您不能添加允许表单将多个$\u GET变量压缩到一个数组中的属性。

您可以使用jquery执行以下操作:

<script>
function sendtheform(){

var theurldata = $("input.MyCBclass").map(function() {
   return $(this).val();
}).get().join(",");

window.location ='yoururl.html?MyCB='+theurldata;
}
</script>
<script>
function sendtheform(){

var theurldata = $("input.MyCBclass").map(function() {
   return $(this).val();
}).get().join(",");

window.location ='yoururl.html?MyCB='+theurldata;
}
</script>
<input name="MyCB" class="MyCBclass" type="checkbox" value="1">
<input name="MyCB" class="MyCBclass" type="checkbox" value="2">
<input onClick="sendtheform()" type="button">
yoururl.html?MyCB=1,2