2015-09-04 96 views
0

我有一个input列表name和默认情况下隐藏。 我显示他们显示基于select价值,我想禁用隐藏的输入,所以他们不会冲突,当我提交表单。 我该怎么做?隐藏的输入不能发送

JS

<script type="text/javascript"> 
    $(document).ready(function() { 
     $("#report_type").change(function() { 
      $("#type_wrap > input").hide(); 
      $("#" + $(this).val()).show(); 

     }); 
    }); 
    </script> 

回答

0

input尝试属性disabled设置为true使用.prop("disabled", true)

$(document).ready(function() { 
     $("#report_type").change(function() { 
      $("#type_wrap > input").prop("disabled", true).hide(); 
      $("#" + $(this).val()).show(); 

     }); 
    }); 
+0

如果我把'.prop输入将不显示()'之间。 – jhunlio

+0

@jhunlio可以在问题中包含'html'吗? – guest271314

+0

你的答案正在工作,当我尝试jsfiddle也许我的jQuery是问题 – jhunlio

1

如果您希望禁用的输入元素,设置它的disabled属性true。要重新启用它,设置它的disabled属性false

$("#type_wrap > input").hide().prop('disabled', true); 
$("#" + $(this).val()).prop('disabled', false).show(); 

注:浏览器是不应该在提交表单时包括残疾输入元素的值。 (reference

0

尝试移除或隐藏元件

删除

$("#type_wrap > input").remove(); 

禁用

$("#type_wrap > input").prop('disabled', true); 

这会阻止元素提交。

1

你想禁用不可见的输入?

我在想

$("#type_wrap > input").not("visible").prop("disabled",true) 

但这是简单

$(function() { 
    $("#report_type").on("change",function() { 
     $("#type_wrap > input").prop("disabled",true).hide(); 
     $("#" + $(this).val()).prop("disabled",false).show(); 
    }); 
});