我正在使用 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/