gpt4 book ai didi

javascript - JSON.stringify 函数在 IE8 中序列化空 DOM 元素时返回 "null"

转载 作者:行者123 更新时间:2023-11-29 18:25:33 24 4
gpt4 key购买 nike

我的页面中有一个弹出对话框,其中包含大约 20 个字段。可以修改 20 个字段,对对话框的任何更改都将更新到服务器。

仅在 IE8 中,当用户尝试清除字段并保存内容时,字段值将设置为 null

似乎使用 IE8 的原生 JSON.stringfy 函数序列化 empty DOM 元素的值正在返回 "null" (字符串) “”

演示: http://jsfiddle.net/6VKzy/2/ [IE8打开]

博客中有关该问题的更多详细信息,

With native JSON support enabled in IE8, users can now take advantage of the built-in JSON.stringify and JSON.parse methods to serialize and deserialize JScript values to JSON text and vice versa. However, there is a known issue in IE8’s native JSON implementation, wherein if a user tries to read the value of an empty DOM element, and serialize the same using native JSON, the result is not the same as a user would expect while serializing "".

http://blogs.msdn.com/b/jscript/archive/2009/06/23/serializing-the-value-of-empty-dom-elements-using-native-json-in-ie8.aspx

注意:这个问题是 self 回答的。

最佳答案

修复方法是使用如下所示的审查函数返回 "" 而不是 "null"

function(k, v) { return v === "" ? "" : v }

固定演示: http://jsfiddle.net/6VKzy/3/ [在 IE8 中打开以验证修复]

博客中的更多详细信息和不同的修复方法,

This is a bug in the production version of IE8. The problem here is that within the DOM a special encoding is used to represent a missing string value. Even though this special value is different from the encoding of the JScript literal "", throughout the JScript implementation the value is treated as being === to "", except for a specific case in JSON.stringify.

Since this special value only originates from accesses to DOM objects, a workaround would be to explicitly censor them on every DOM access that might return one.

http://blogs.msdn.com/b/jscript/archive/2009/06/23/serializing-the-value-of-empty-dom-elements-using-native-json-in-ie8.aspx

关于javascript - JSON.stringify 函数在 IE8 中序列化空 DOM 元素时返回 "null",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13850170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com