Safari javascript对象未更新

Safari javascript对象未更新,javascript,object,safari,Javascript,Object,Safari,我有一段代码可以在除safari之外的所有浏览器上运行 基本上我有一个叫做记录的对象。 记录有属性、用户电话、用户传真等。 我还有一个具有相同字段名的表单。 我更新文本字段中的对象模糊 $(this).on('blur', function() { console.log($(this).val()); // shows the new value correctly console.log($(this).attr('name')); // shows the right na

我有一段代码可以在除safari之外的所有浏览器上运行

基本上我有一个叫做记录的对象。 记录有属性、用户电话、用户传真等。 我还有一个具有相同字段名的表单。 我更新文本字段中的对象模糊

$(this).on('blur', function() {
    console.log($(this).val()); // shows the new value correctly
    console.log($(this).attr('name')); // shows the right name correctly
    record[$(this).attr('name')] = $(this).val();
    console.log(record); // shows the record with the old value, should show the new value
    updateDB();
});
代码中的注释显示我在控制台中得到的内容。 此代码在其他浏览器中工作。 有什么想法吗?

这应该行得通:

$(this).on('blur', function() {
    console.log($(this).val()); // shows the new value correctly
    console.log($(this).attr('name')); // shows the right name correctly
    var key = $(this).attr('name'),
        val = $(this).val();
    record[key] = val;
    console.log(record); // shows the record with the old value, should show the new value
    updateDB();
});
我想你的范围有点模糊

而且,与您的代码类似,我没有任何问题


编辑:和。这样做的好处应该是避免以后使用内联javascript和绑定元素。

谢谢Ashesh,但对我来说不起作用。你的小提琴在同一个浏览器上工作,但不是我的代码。我有Safari和Chrome的屏幕截图显示了两者的区别,但我不知道如何在这个论坛中放置图像。这是整个功能的一部分,它对文本框启动onblur,对选择框启动onchange;函数UpdateRecord(elm){var val=$(elm).val();var key=$(elm).attr('name');record[key]=val;console.log(record);}下面是其中一个文本框: