Discuss / JavaScript / 作业

作业

Topic source

ClarenceYK

#1 Created at ... [Delete] [Delete and Lock User]
json = '{ ' + $('form#test-form :input[type!=submit]').map(function () {
  if (this.type === 'radio') {
    if (this.checked) {
      return this.name + ': ' + this.value;
    }
  } else if (this.type === 'select-one') {
    return this.name + ': ' + $(this).find('option[selected]')[0].value;
  } else {
    return this.name + ': ' + this.value;
  }
}).get().join(', ') + ' }';

沐汐时

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

这里的get()方法是什么作用?

荆可可

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

把map返回的jquery对象(是个类Array 对象)转换成Array 参考http://stackoverflow.com/questions/4795318/map-get-confusion

aiyicha

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

.find('option[selected]')[0].value

这儿不对,selected是固定默认选择,应该和其他input一样用this.value就可以的


  • 1

Reply