我使用css-element-queries(https://github.com/marcj/css-element-queries)根据元素的大小应用样式,但我也通过ajax调用动态添加元素。通过ajax加载的元素没有正确设置样式,可能是因为在执行css-element-queries脚本时它们不存在。 css-element-queries在window.load上自动运行,所以我不清楚如何在ajax调用成功后运行它。我使用jquery,所以欢迎特定于jquery的响应。
答案 0 :(得分:1)
css-element-queries有一个解决方法。
可以强制执行window.load事件,
dispatchEvent(new Event('load'));
但它已弃用,可能会将Ajax圈成循环,除非你的ajax没有被onload事件完成。 IE旧学校netscape 2,document.write方法。
document.write("<script src='ajax.js'><"+"/"+"script>");