我有一个搜索表单: -
<form method="get" action="/jobs/">
<select name="job_sector">
<option value="">All sectors</option>
<option value="Finance">Finance</option>
<option value="Human Resources">Human Resources</option>
<option value="Procurement & Supply Chain">Procurement & Supply Chain</option>
<option value="Sales & Marketing">Sales & Marketing</option>
</select>
<select name="job_salary_from">
<option value="0">Salary range</option>
<option value="10000">£10,000 - £19,999</option>
<option value="20000">£20,000 - £29,999</option>
<option value="30000">£30,000 - £49,999</option>
<option value="50000">£50,000 - £69,999</option>
<option value="70000">£70,000 - £99,999</option>
<option value="100000">£100,000+</option>
</select>
</div>
<div class="col-md-6">
<select name="job_type">
<option value="">All job types</option>
<option value="Permanent">Permanent</option>
<option value="Temporary">Temporary</option>
<option value="Interim">Interim</option>
</select>
<select name="job_location">
<option value="">All job locations</option>
<option value="Leicestershire">Leicestershire</option>
<option value="Nottinghamshire">Nottinghamshire</option>
<option value="Derbyshire">Derbyshire</option>
<option value="Lincolnshire">Lincolnshire</option>
</select>
<input id="search-jobs" name="job_search" type="text" placeholder="Search DISTINCT for jobs e.g. Accountant">'
</form>
如果我在未设置任何内容的情况下执行搜索,则URL将变为: -
http://website.dev/jobs/?job_sector=&job_salary_from=0&job_type=&job_location=&job_search=
如果值为空,是否有任何方法不在URL中显示这些内容,因此搜索网址将变为:
如果未设置任何值,则: -
http://website.dev/jobs/?job_sector=finance
如果只选择了一个值。
修改
我试过了: -
jQuery("form").submit(function(){
jQuery("input").each(function(index, obj){
if(jQuery(obj).val() == "") {
jQuery(obj).remove();
}
});
});
但它似乎仍然不起作用。