Discuss / JavaScript / 怎样选radio里面checked值才优雅?

怎样选radio里面checked值才优雅?

Topic source

光光dane

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

radio的值使用相同的key覆盖掉,好像很龊。。

var fields = $("#test-form :input");
var checked = $("#test-form :radio:checked")

var values = {}
fields.each(function () {
  values[this.name] = $(this).val();
});

values['gender'] = checked.val();
console.log(values);
json = JSON.stringify(values);

王政亮WZL

#2 Created at ... [Delete] [Delete and Lock User]
var fields = $("#test-form :input:not(button)");

否则 button 也进去了,多一个空的 key: value


  • 1

Reply