【发布时间】:2014-03-25 02:50:48
【问题描述】:
我的本地存储功能始终将“3”的单选按钮值存储在本地存储中,无论做出何种选择,我都不知道为什么。其他所有元素都正确存储。
请看我的小提琴以显示我的问题:http://jsfiddle.net/3u7Xj/148/
我的功能:
$('input, select, textarea').each(function() {
var value = $(this).val();
var name = $(this).attr('name');
if ($(this).hasClass('checkers')) {
value = $(this).is(":checked");
if (value) {
value = 'on';
} else {
value = 'off';
}
}
if (this.name.match(/^multiselect_/)) {//removes buggy append
return false;
}
console.log('Saving');
console.log(name + ':' + value);
Survey[name] = value;
});
if (localStorage.getObj('Surveys') !== null) {
Surveys = localStorage.getObj('Surveys');
}
Surveys[$('#FirstName').val() + '.' + $('#LastName').val()] = Survey; //store in big list
localStorage.setObj('Surveys', Surveys);
【问题讨论】:
-
为什么我被否决了
-
我也不明白反对意见;这是一个关于代码的好问题,它有一个小提琴。
标签: javascript jquery html radio-button local-storage