从表单提交非空字段 [英] Submit only non empty fields from Form
本文介绍了从表单提交非空字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是表格:
< form action =method =GET>
< input type =textname =para1>
< input type =textname =para2>
< input type =submitvalue =search>
< / form>
现在当我填写第一个字段时,我会获得 example.com/?para1=值& para2 =
但我只是希望它是 example.com/?para1=value ,因为para2不包含值。我怎样才能做到这一点?应该可以用JS或任何东西?
解决方案
试试这个,
包含jQuery并使用下面的代码片段。
$(document).ready(function(){
$( (){
if($(obj).val()==){function(){
$(input)。
$(obj).remove();
}
});
});
});
That is the form:
<form action="" method="GET">
<input type="text" name="para1">
<input type="text" name="para2">
<input type="submit" value="search">
</form>
Now when I fill out only the first field I get example.com/?para1=value¶2= But I just want it to be example.com/?para1=value because para2 don't contains value. How can I do this? Should be possible with JS or anything?
解决方案
Try this,
Include jQuery and use following snippet.
$(document).ready(function(){
$("form").submit(function(){
$("input").each(function(index, obj){
if($(obj).val() == "") {
$(obj).remove();
}
});
});
});
这篇关于从表单提交非空字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文