如何确保所有元素都加载在html页面上,然后我们对CSS中的元素进行一些修改

How to ensure that all elements are loaded on an html page, and then we perform some modifications on elements in CSS?

本文关键字:元素 CSS 我们 然后 修改 确保 何确保 html 加载      更新时间:2023-09-26

这是一个以前问过很多次的通用问题。我之所以问这个问题,是因为我确实在jquery中使用了onready回调,并且它没有修改我的元素"search_input"的占位符

$( document ).ready(function() {
  $("#search_input").attr('placeholder','New data that will be shown');
}

这是因为CSS在加载之前应用于id"search_input"。我什么都试过了,但似乎都不管用。

有什么想法吗?

注意:我正在为使用ERSI地图的应用程序开发ArcGIS Javascript。我面临的问题是,当我通过javascript加载搜索栏时,加载搜索栏需要时间。但是,在加载此脚本之前,我的html页面会调用onready回调。因此,我面临这个问题。我无法解决这个问题,任何帮助都将不胜感激!

我在代码中使用修复了这个问题

search.on("load", function () {
//push all the sources
  var sources = search.sources;
  sources.push(addSources("ABC","ABC","eg : ABC",1));
  sources.push(addSources("XYZ","XYZ","eg: XYZ",1));
  search.set("sources", sources);
  //Adding the placeholder here, as the search bar is loaded with sources only at this point of the execution
  //Hence, we can modify the CSS only after this point.
  $("#search_input").attr('placeholder','Search Tree Data');
  });

您不能在代码中的任何位置修改CSS。只有当搜索栏加载了所有源时,才需要对其进行修改。我尝试添加$document.ready(function(){});或者在正文末尾添加css。没有任何效果,因为我们在这里使用了一个不同的javascript库/工具包——Dojo。因此,我们只能根据数据的加载方式或何时在Dojo中调用回调来执行操作。而不是在jQuery的普通HTML javascript中。