我正在尝试在创建特定div时使函数关闭.用最简单的术语来说,我有这样的事情:
<a href="" id="foo">Click me!</a>
<script>
$("#foo").live("click",function(e) {
e.preventDefault();
$(this).append($("<div />").html("new div").attr("id","bar"));
});
</script>
Run Code Online (Sandbox Code Playgroud)
以前,我有突变事件听取div#bar的创建 - 这样的事情:
$("#bar").live("DOMNodeInserted", function(event) {
console.log("a new div has been appended to the page");
});
Run Code Online (Sandbox Code Playgroud)
是否有使用Mutation Observers的等价物?我尝试了attrchange.js功能你可以在DOM元素的样式对象更改后有一个javascript钩子触发器吗?但该插件仅检测元素何时被修改,而不是何时创建.
目前,由于安全策略,Chromium无法通过ajax读取本地文件--allow-file-access-from-files.但我目前需要创建一个Web应用程序,其中数据库是一个xml文件(在极端情况下为json),位于一个带有index.html的目录中.可以理解,用户可以在本地运行该应用程序.是否有解决xml-(json-)文件的解决方法,而不将其包装在函数中并更改为js扩展名?
loadXMLFile('./file.xml').then(xml => {
// working with xml
});
function loadXMLFile(filename) {
return new Promise(function(resolve, reject) {
if('ActiveXObject' in window) {
// If is IE
var xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async = false;
xmlDoc.load(filename);
resolve(xmlDoc.xml);
} else {
/*
* how to read xml file if is not IE?
* ...
* resolve(something);
*/
}
}
}
Run Code Online (Sandbox Code Playgroud) 我在 json 文件中有一组对象。我正在尝试将此文件导入另一个文件,以便我可以在一个简单的反应项目中引用数据。
我尝试了导出默认值和命名导出的各种组合,但是 JSON 文件在我保存时总是抱怨。这是我想要实现的目标:
(File1.json)
[
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
]
Run Code Online (Sandbox Code Playgroud)
文件2.js
[
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem …Run Code Online (Sandbox Code Playgroud)