javascript - 我不断收到“TypeError:未定义不是对象”错误消息
问题描述
我一直在尝试制作一个脚本,让用户在他们的 iOS 或 iPadOS 设备上安装配置文件,我的代码是:
function downloadProfile(profileName, configurationProfile) {
var element = document.createElement("a");
element.setAttribute("href", "data:application/x-apple-aspen-config," + encodeURIComponent(configurationProfile));
element.setAttribute("download", profileName + ".mobileconfig");
element.body.appendChild(element);
element.click();
element.body.removeChild();
}
问题是,我不断收到一条错误消息说Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'element.body.appendChild')
。有谁知道修复?当然,这不是整个代码,它只是我需要帮助的部分。
解决方案
您创建的元素没有属性主体。我假设您想将新元素添加到文档中,如下所示:
document.body.appendChild(element);
检查你的例子:https ://www.w3schools.com/jsref/met_document_createelement.asp
推荐阅读
- bash - 循环遍历 bash 数组以使用 jq 添加新数据——只看到最后的更改
- loops - Stata如何在循环中使用'file`导出分隔文件
- python - 从文本中获取所有可能的单词
- c++ - 为什么 T& 类型的模板参数解析为 T?
- node.js - npm install 不起作用,因为某些包不包含 package.json 文件
- python - 如何在scrapy python中提取带有数字的内部链接
- mysql - 用于空间查询的 Jhipster 生成的 Spring Boot + MySql 项目配置
- reactjs - useEffect 依赖列表及其包含所有使用变量的最佳实践
- xml - 如何在scala中单独处理大xml有效负载的块
- javascript - Converting Function Base Component into Class Base Component