I am trying to create a program which saves info about an element into a new JavaScript Object, or really into any sort of object from any language. Here's an example. Somebody clicks a create button and It prompts them to name a CSS Class. After that, they are asked to fill out a form wi开发者_如何学Pythonth a list of properties. How ever, the properties need to be saved to Local place because it is meant to be a static page they will be working on, without an account. Basically, this is what I am asking. Is there a way to create a 'static' object in JavaScript, that will be only created once the form is filled out and has a unique name. There will need to be multiple made most likely. Here's the format I was thinking
document.formname.blah.value = {
type=document.formname.id.value;
border='1px solid #000'
}
I know I am little hard to understand I am sorry. But does anybody know a way for me to do this??
I'm not quite sure whether I get it right, but how about an basic javascript object stored in a global variable?
window.blah = {
type: document.formname.id.value,
border: '1px solid #000'
};
If you want to assign that object to a dom node, you can use jquery's data()
method:
var blah = { ...(see above).. };
$(document.formname.blah).data('whateverThisIs', blah);
I actually found a way! It was pretty simple actually. It is when a new element is created, a new object is created called element, and from there that element is pushed into an array. So what happens is you end up with an array with Objects in it that can be accessed using a simple for loop or a dom This function. Thanks though!
精彩评论