如何从查询字符串的表单中删除空字段? [英] How can I remove empty fields from my form in the querystring?

查看:160
本文介绍了如何从查询字符串的表单中删除空字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表单,有四个输入。当我提交表单时,我想使用GET http方法。



例如:

  aaa:foo 
bbb:____
ccc:bar
ddd:____

我想要这个查询字符串:

  /?aaa = foo& ccc = bar 

问题是我有这个查询字符串:

  /?aaa = foo& bbb =& ccc = bar& ddd = 
pre>

如何从查询字符串的表单中删除空字段?



谢谢。

解决方案

您可以使用jQuery的提交函数来验证/更改您的表单:

 < form method =getid =form1> 
< input type =textname =aaaid =aaa/>
< input type =textname =bbbid =bbb/>
< input type =submitvalue =Go/>
< / form>
< script type =text / javascript>如果($(#bbb).val())提交(函数(){
$(document).ready(function(){
$(#form1 ==){
$(#bbb)。remove();
}
});
});
< / script>


I have a simple form with four inputs. When I submit my form, I want to use the GET http method.

For the example :

aaa : foo
bbb : ____
ccc : bar
ddd : ____

I want to have this query string :

/?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 ?

Thanks.

解决方案

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>

这篇关于如何从查询字符串的表单中删除空字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆