清除本地存储以进行div选择时的div [英] Clear local storage for div on radio selection
本文介绍了清除本地存储以进行div选择时的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户选择否"单选按钮时,我正在尝试获取本地存储以清除一个特定div中的所有字段:
I'm trying to get local storage to clear for all fields in one specific div when the user selects the No radio button:
jsfiddle 稍微不完整,但应该可以解决问题
Slightly incomplete jsfiddle but should do the trick
我显然不是在这里做某事(.hide-show-yes
是我要清除该div中所有字段的地方):
I'm obviously not doing something right here (.hide-show-yes
is where I want all fields inside that div to clear):
$(document).ready(function(){
$('input[name="for_person"]').on('click', function () {
if ($('#personNo').prop('checked')) {
// ??
$('.hide-show-yes').localStorage.removeItem('fname');
} else {
// do nothing
}
});
});
推荐答案
localStorage
不是jQuery方法.也是
localStorage
is not a jQuery method . Also
$(document).ready([function() {
if (localStorage["dontclear"]) {
$('#dontclear').val(localStorage["dontclear"]);
}
if (localStorage["fname"]) {
$('#fname').val(localStorage["fname"]);
}
if (localStorage["lname"]) {
$('#lname').val(localStorage["lname"]);
}
console.log(localStorage)
}, function() {
$('.stored').change(function() {
localStorage[$(this).attr('name')] = $(this).val();
console.log(localStorage)
});
$('input[name="for_person"]').on('click', function() {
if ($('#personNo').prop('checked')) {
// ??
localStorage.removeItem('fname');
} else {
// do nothing
}
});
}]);
plnkr http://plnkr.co/edit/LPw3zbpgrhJkSh1hdKXG?p=info
这篇关于清除本地存储以进行div选择时的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文