【发布时间】:2011-10-05 23:49:42
【问题描述】:
我想要这样的功能
// get the value of a form element the way it would be submitted
// by the form
function getVal(fieldName) {
var $field = $(':input[name=' + fieldName + ']');
// radio buttons
if ($field.is(':radio')) {
return $(':input[name=' + fieldName + ']:checked').val();
}
// textarea, input[type=text], select
else {
return $field.val();
}
}
上面的工作很好,因为它处理单选按钮和其他类型的表单输入(不是复选框,但我暂时不关心)。
我想知道 jquery 是否还没有我应该使用的内置函数或选择器?因为对我来说,单选按钮在功能上与选择完全相同(单选)。我不明白为什么我应该区别对待
【问题讨论】:
标签: jquery forms input radio-button