javascript - 无法在运行时在 Windows 8 应用程序中显示/隐藏 html 元素

标签 javascript jquery windows-8

我正在使用 jQuery 制作 Windows 8 应用程序 (JavaScript)。但是 Visual Studio 不允许我显示或隐藏不同的元素(div、span 等),并出现以下错误消息:

Unable to add dynamic content ' A script attempted to inject dynamic content, or elements previously modified dynamically, that might be unsafe. For example, using the innerHTML property to add script or malformed HTML will generate this exception.Use the toStaticHTML method to filter dynamic content, or explicitly create elements and attributes with a method such as createElement.

我刚刚写了下面的代码:

$(document).ready(function () {
    $('#names').fadeIn();
});

最佳答案

Windows 8 安全模型不允许通过 innerHTML 或类似函数将动态内容添加到 DOM。不幸的是,当您在页面中包含 jQuery 时(在 jQuery.support 的设置期间),这种情况会发生几次。

唯一的解决方案是重写部分 jQuery(这可能很烦人),或者使用已经针对 Windows 8 重新配置的 jQuery 版本,例如 jQuery for Windows 8 , 通过 appendTo.

坦白说,我参与了这个特定项目。

关于javascript - 无法在运行时在 Windows 8 应用程序中显示/隐藏 html 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13571913/

相关文章:

jquery - 照片网格仅显示一些图像

c# - 当 Surface 键盘显示在 Windows 8 商店应用程序中时,弹出窗口不会向上移动

javascript - 如果字符串包含超过 2 位小数,则用于替换字符串的正则表达式

javascript - jquery 跳过具有特定 css 类的表

javascript - 我可以在 Javascript 中将 "extend"定义为闭包定义的 "class"吗?

jquery - JavaScript JSON 问题

c - 如何在 Windows 8 上安装 C 编译器?我不想使用 IDE

c# - WinRT - 以编程方式跳转到 C# 代码中的下一个控件

java - 防止用户看到以前提交的信息

javascript - 链接和 JS 重定向,导致在 Office JS 加载项中打开一个新窗口