Javascript 服务器端没有任何区别,但它提供了更好的URL。我使用chrome,禁用表单中的输入意味着它们不会被发送。我认为这自2010年以来没有改变。通过删除“名称”属性执行此操作的问题是,它无法切换,即一旦删除名称,就无法将其添加回,除非您将其保存在某个位置。这对我

Javascript 服务器端没有任何区别,但它提供了更好的URL。我使用chrome,禁用表单中的输入意味着它们不会被发送。我认为这自2010年以来没有改变。通过删除“名称”属性执行此操作的问题是,它无法切换,即一旦删除名称,就无法将其添加回,除非您将其保存在某个位置。这对我,javascript,jquery,forms,Javascript,Jquery,Forms,服务器端没有任何区别,但它提供了更好的URL。我使用chrome,禁用表单中的输入意味着它们不会被发送。我认为这自2010年以来没有改变。通过删除“名称”属性执行此操作的问题是,它无法切换,即一旦删除名称,就无法将其添加回,除非您将其保存在某个位置。这对我更有效,因为当我按Enter键时,它会考虑聚焦输入字段中新编辑的值。这是正确的答案。不考虑新编辑的值。小的改进:dothis.disabled=this.disabled | | this.value以避免意外启用其他禁用的输入。花了我半个小时


服务器端没有任何区别,但它提供了更好的URL。我使用chrome,禁用表单中的输入意味着它们不会被发送。我认为这自2010年以来没有改变。通过删除“名称”属性执行此操作的问题是,它无法切换,即一旦删除名称,就无法将其添加回,除非您将其保存在某个位置。这对我更有效,因为当我按Enter键时,它会考虑聚焦输入字段中新编辑的值。这是正确的答案。不考虑新编辑的值。小的改进:do
this.disabled=this.disabled | | this.value以避免意外启用其他禁用的输入。花了我半个小时。。。
http://localhost:3000/quizzes?subject=English
http://localhost:3000/quizzes?term=&subject=English&topic=&age_group_id=&difficulty_id=&made_by=&order=&style=
  quizSearchForm = jQuery("#searchForm");
  formParams = quizSearchForm.serializeArray();
  //remove any empty fields from the form params before submitting, for a cleaner url
  //this won't work as we're not changing the form, just an object made from it.
  for (i in formParams) {
    if (formParams[i] === null || formParams[i] === "") {
      delete formParams[i];
    }
  }
  //submit the form
function submitSearchForm(){
  quizSearchForm = jQuery("#searchForm");
  //disable empty fields so they don't clutter up the url
  quizSearchForm.find(':input[value=""]').attr('disabled', true);
  quizSearchForm.submit();
}
$('#searchForm').find('input, textarea, select').each(function(_, inp) {
  if ($(inp).val() === '' || $(inp).val() === null)
    inp.disabled = true;
  }
});
$(':input[value=""]').attr('disabled', true);
$('form#searchForm').submit(function() {
    $(':input', this).each(function() {
        this.disabled = !($(this).val());
    });
});
// Loop through empty fields and disable them to prevent inclusion in array
$('#OptionB input, select').each(function(){
    if($(this).val()==''){
        $(this).attr('disabled', true); 
    }
});

// Collect active fields into array to submit
var updateData = $('#OptionB input, select').serializeArray();
$('form').submit(function(){
    $(this).find('input[name], select[name]').each(function(){
        if (!$(this).val()){
            $(this).removeAttr('name');
        }
    });
});
$('form').submit(function(){
    $(this).find('input[name], select[name]').each(function(){
        if (!$(this).val()){
            $(this).data('name', $(this).attr('name'));
            $(this).removeAttr('name');
        }
    });
});

function recoverNames(){
    $(this).find('input[name], select[name]').each(function(){
        if ($(this).data('name')){
            $(this).attr('name', $(this).data('name'));
        }
    });
}
$("#form").submit( function(e){
    e.preventDefault();
    //convert form to query string, i.e. a=1&b=&c=, then cleanup with regex
    var q = $(this).serialize().replace(/&?[\w\-\d_]+=&|&?[\w\-\d_]+=$/gi,""),
    url = this.getAttribute('action')+ (q.length > 0 ? "?"+q : "");
    window.location.href = url;
});