0

我有 HTML 格式的标准联系表格:

<input type="text" class="text" value="" name="username" id="username" />

为了在发生错误时返回值,我使用了 localstorage:

$(document).ready(function() {

var item = window.localStorage.getItem('username');
$('input[name=username]').val(item);
$('input[name=username]').change(function() {
   window.localStorage.setItem('username', $(this).val());
});

问题出在 Internet Explorer 中。当我第一次使用联系表单打开我的页面时,所有字段的值都名为“NULL”。有没有办法让我删除它?

谢谢

4

1 回答 1

1

检查该值是否null在设置之前使用.val()?

if ( item !== null ) $('input[name=username]').val(item);
于 2013-01-14T18:42:22.230 回答