Discuss / JavaScript / 看了评论才理清

看了评论才理清

Topic source

_啊狗

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

var obj ={};

$('#test-form :input').filter(function(){

return this.type !=='submit' || this.checked

}).map(function(){

return obj[this.name] = this.value;

})

json = JSON.stringify(obj);

SeanP

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

你这有BUG,修正如下 

var obj ={};

$('#test-form :input').filter(function(){

if (this.type !=='submit' &&this.type !== 'radio')

{

return this;

} else if (this.type === 'radio' &&  this.checked) {

return this;

}).map(function(){

return obj[this.name] = this.value;

})

json = JSON.stringify(obj);


  • 1

Reply