本文介绍了如何从查询字符串中的表单中删除空字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有四个输入的简单表单.当我提交表单时,我想使用 GET http 方法.
I have a simple form with four inputs. When I submit my form, I want to use the GET http method.
例如:
aaa : foo
bbb : ____
ccc : bar
ddd : ____
我想要这个查询字符串:
/?aaa=foo&ccc=bar
问题是我有这个查询字符串:
The problem is I have this query string :
/?aaa=foo&bbb=&ccc=bar&ddd=
如何从我的表单中的查询字符串中删除空字段?
How can I remove empty fields from my form in the query string ?
谢谢.
推荐答案
您可以使用 jQuery 的 submit 功能来验证/更改您的表单:
You could use jQuery's submit function to validate/alter your form:
<form method="get" id="form1">
<input type="text" name="aaa" id="aaa" />
<input type="text" name="bbb" id="bbb" />
<input type="submit" value="Go" />
</form>
<script type="text/javascript">
$(document).ready(function() {
$("#form1").submit(function() {
if($("#bbb").val()=="") {
$("#bbb").remove();
}
});
});
</script>
这篇关于如何从查询字符串中的表单中删除空字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!