//create a class
function Person(name, age) {
this.name = name || "";
this.age = age || 0;
}
Person.prototype = new Person;
var john = new Person("John", 29);// add some custom properties
john.language = "English";
john.wife = "Mary";//Enumerate using the standard forEach method:
for(prop in john)
{
str+=prop + " value :"+ john[prop]+"\n";//Concate prop and its value from object
}
alert(str);
or
var obj = objFrm.elements["name"];
var str=""; //variable which will hold property values
for(prop in obj)
{
alert(prop);
str+=prop + " value :"+ obj[prop]+"\n";//Concate prop and its value from object
}
alert(str); //Show all properties and its value
沒有留言:
張貼留言