简体   繁体   English

jQuery序列化和serializeArray不适用于谷歌浏览器

[英]Jquery serialize and serializeArray is not working with google chrome

I have following html. 我有以下HTML。

<fieldset id="fieldset-step_3">   
       <input type="text" value="2" id="rule_form-lead_time" name="rule_form[lead_time]"> 
       <select class="w50" id="rule_form-operator" name="rule_form[operator]">
            <option label="&lt;" value="&lt;">&lt;</option>
            <option selected="selected" label="&gt;" value="&gt;">&gt;</option>
       </select>
       <button type="button" id="next" name="next">Next</button>
</fieldset>

I use following jquery code for get values when click next button. 单击下一步按钮时,我使用以下jquery代码获取值。

   $('#next').click(function () {
        var values = $('#fieldset-step_3').serialize();
        alert(values);          
   });

This code working for firefox 8 and opera 11.60 beta. 此代码适用于Firefox 8和Opera 11.60 beta。 But it does not work for google chrome 15.0.874.121. 但它不适用于谷歌浏览器15.0.874.121。

Please help me. 请帮我。 Give me another idea for get field-set values from jquery. 给我另一个从jquery获取字段集值的想法。

You seem to have found a bug. 您似乎发现了一个错误。 I tried this in Chrome 11 and saw the same thing. 我在Chrome 11中尝试了此操作,并看到了相同的内容。 If I serialize the form, it works. 如果我序列化表格,它可以工作。 If I serialize individual form elements, it works. 如果我序列化单个表单元素,它将起作用。 If I try to serialize a div containing all of the form elements, or your fieldset tag, it doesn't. 如果我尝试序列化包含所有表单元素的div或您的fieldset标签,则不会。

I run into this today. 我今天碰到这个。 $('#formid').serialize(); $( '#formid')序列化()。 works fine with firefox,but nothing came out in chrome. 在Firefox上可以正常工作,但Chrome没有任何效果。 After some tests,here's my answer: 经过一些测试,这是我的答案:

in chrome,the form name and id must be the same to make serialize work. 在chrome中,表单名称和ID必须相同才能使序列化工作。

This is quite a simple way, but does the job, and u can customize it the way u want. 这是一种非常简单的方法,但是可以完成工作,并且您可以按照自己的方式自定义它。

parseField = function( $object ){
  result = new Array();
  $object.find('select[value!=""], input[value!=""]').each(function(){
    var obj = {};
    obj.key = $(this).attr('name');
    obj.val = $(this).val();
    result.push( obj );
  });
  return result;
}

You can use it like: 您可以像这样使用它:

var values = parseField( $('#fieldset-step_3') );
$.each(values, function(i,obj){
  alert( 'My key is: ' + obj.key + ' and my value: ' + obj.val );
});

mmm try adding 嗯,尝试添加

<input type="text" value="2" id="rule_form-lead_time" name="rule_form[lead_time]" />

insted of 装的

<input type="text" value="2" id="rule_form-lead_time" name="rule_form[lead_time]">

when validating this i found 当验证这个我发现

end tag for "input" omitted, but OMITTAG NO was specified

…ut type="text" value="2" id="rule_form-lead_time" name="rule_form[lead_time]"> 


You may have neglected to close an element, or perhaps you meant to "self-close" an element, that is, ending it with "/>" instead of ">".

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery 2.2 serializeArray()可在Firefox,Chrome中运行,但不能在IE(11)中运行 - jquery 2.2 serializeArray() working in Firefox, Chrome, but not IE(11) SerializeArray进行序列化 - SerializeArray to Serialize jQuery从不是表单的元素序列化/ serializeArray - jQuery serialize / serializeArray from an element that is not a form 发布者 jQuery serialize() / serializearray() 不包括 textarea - Post by jQuery serialize() / serializearray() excluding textarea 在jQuery serialize()或serializeArray()中向Ajax POST添加/ push()值 - Adding/push() Values to Ajax POST in jQuery serialize() or serializeArray() Ajax jQuery serialize() 和 serializeArray() textarea 未以 Django 形式提交 - Ajax jQuery serialize() & serializeArray() textarea not submitting in Django form Ajax jQuery不适用于Google Chrome - Ajax jQuery not working for Google Chrome jQuery脚本在Google Chrome中不起作用 - jQuery script not working in google chrome .live 不能在 Google Chrome 中的 jQuery 中工作,但可以在 IE 中工作 - .live not working in jQuery in Google Chrome but working in IE 如果使用Jquery SerializeArray()为空,如何序列化复选框,单选和多个选择元素? - How Can I Serialize the checkbox, radio and multiple select elements if they are blank using Jquery SerializeArray()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM