我有一个包含几个可见和隐藏输入字段的获取表单。提交表单时,选定的字段及其值将按照它们在表单中的放置顺序附加到 url。有没有办法使用 jQuery 重新排序 url 中的参数?请注意,出于可用性的原因,我不能对表单本身的元素重新排序。
我知道它引出了“我为什么要这样做?”的问题,但原因是我将访问静态页面,因此参数的顺序必须与它们在静态页面 url 中的完全一致。例如,我的表单返回一个 url:
http://someurl?names=comm&search=all&type=list
而静态页面有一个网址:
http://someurl?search=all&type=list&names=comm
一个简化的表单示例在这里:
<form id="search_form" method="get" action="http://www.cbif.gc.ca/pls/pp/ppack.jump" >
<h2>Choose which names you want to be displayed</h2>
<select name="names">
<option value="comm">Common names</option>
<option value="sci">Scientific names</option>
</select>
<h2>Choose how you want to view the results</h2>
<input type="radio" name="search" value="all" id="complete" checked = "checked" />
<label for="complete" id="completeLabel">Complete list</label>
<br/>
<input type="radio" name="p_null" value="house" id="house" />
<label for="house" id="houseLabel">House plants only</label>
<br/>
<input type="radio" name="p_null" value="illust" id="illustrat" />
<label for="illustrat" id="illustratLabel">Plants with Illustrations</label>
<br/>
<input type="hidden" name="type" value="list" />
<input type="submit" value="Submit" />
</form>
我可以使用 $(#search_form).serializeArray() 获取具有值的表单字段并像我想要的那样按摩数组,但我不知道如何将其设置回来,即修改序列化值以便提交的 url 有我的参数的顺序。我什至不确定这是否是正确的方法,所以任何指针都将不胜感激。