[英]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="<" value="<"><</option>
<option selected="selected" label=">" value=">">></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.