The function Xtool (id, MSG) {
This. Id=id;
This. MSG=MSG;
}
.
New Xtool (" x1 ", "1234567")
Then the js, how to find a object?
Can you find like this? Eval (" x1 "), the document. The getElementById (" x1 ")
But can't. How do I find?
CodePudding user response:
A custom object is not attribute search by id, only new Xtool (" x1 ", "1234567"), the return value of the access object,CodePudding user response:
Js object different from the dom tree, js object in memory don't you return address, how are you going to useCodePudding user response:
A single object creation can use variables to store, var xtool=new xtool (' a ', '1111');This xtool is on behalf of the newly created object
If you want to create multiple objects can use an array to store, can also use a dictionary to store, if id is not repeated dictionary is very convenient,
For example: dic [' a ']=new Xtool (' a ', '1111');
Dic (' a ') is a new object
CodePudding user response:
Understand, thank you.Pressed by, how element to add methods, add event?
The function initMy () {
This style. Diasplay=""
.
}
Then can do this with
Adiv. InitMy ()
More events
Adiv. OnchangeStyle=function ()
CodePudding user response: