I want to add a method to the utility class util.js. When html introduces the js, the generated html is automatically inserted into the html as follows:
function log(obj,text) {
var logId = "testlog";
var div = obj.createElement("div");
div.id = logId;
var logObj = obj.getElementById(logId);
var first=obj.body.firstChild;//
obj.body.insertBefore(div,first);
logObj.style.display = "block";
logObj.style.color = "white";
logObj.style.size = "32px";
logObj.backgroundImage = "url(/popCashierbg.png)";
logObj.innerHTML = text;
}
has the following problems:
-
When
- is called, log (window.docuemt, "werwer") has been unable to find firstChild when obj.body.firstChild reported an error in the page initialization js. Most inserts on the
- network are inserted under the corresponding class or under an id element node, which I want to insert directly under the body.
- the js direct document I introduced is the same object as document in the html initialization code.