您的位置:首页 > 其它

自定义一个序列化表单的方法

2016-09-29 16:22 134 查看
/** 自定义一个序列化表单的方法* */
$.fn.serializeObject = function() {
var o = {};
$(this).find("input").each(function(index) {
if ($(this).attr("name") != undefined) {
if ($(this).attr("type") == "text" || $(this).attr("type") == "password" || $(this).attr("type") == "hidden") {
o[$(this).attr("name")] = $(this).val();
//alert($(this).attr("name")+" : "+$(this).val());
}
if ($(this).attr("type") == "radio") {
if ($(this).is(":checked")) {
o[$(this).attr("name")] = $(this).attr("value");
}
}
if ($(this).attr("type") == "checkbox") {
if ($(this).is(":checked")) {
o[$(this).attr("name")] = $(this).attr("value");
}
}
}
});
$(this).find("select").each(function(index) {
if ($(this).attr("name") != undefined) {
o[$(this).attr("name")] = $(this).val();
}
});

$(this).find("textarea").each(function(index) {
if ($(this).attr("name") != undefined) {
o[$(this).attr("name")] = $(this).val();
}
});
return o;
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐