Discuss / JavaScript / 如果无法理解最简洁那个解决方案,可以这么理解。

如果无法理解最简洁那个解决方案,可以这么理解。

Topic source

牛三金

#1 Created at ... [Delete] [Delete and Lock User]

json = {}; $('#test-form [type!=submit]').map(function(){ if( (this.type !== "radio") || (this.type === "radio" & this.checked ){ json[this.name] = this.value; } }); json = JSON.stringify(json);

这里特别说一下,Gender两个选项的name均为"gender",如果不针对这一点做一个判定,则后面的<input name="gender"...>的value必然会覆盖前者。


  • 1

Reply