javascript动态生成方法

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">javascript

<html xmlns="http://www.w3.org/1999/xhtml">html

<head>java

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />数据结构

<title>动态代码生成测试</title>app

</head>测试

<div id="divtest" ></div>ui

<body>this

</body>spa

<script language="javascript" type="application/javascript" src="../js/closure.js"></script>xml

</html>

          

----js--

// JavaScript Document

var divtest = document.getElementById("divtest");

divtest.style.border="1px solid rgb(0,0,0)";


function User(properties)

{

for(var i in properties)

{

(

function(which)

{

var p =i;

which["get"+p]=function()

{

return properties[p];

}

which["set"+p]=function(val)

{

properties[p]=val;

}

}

)(this);

}

}  

var userObj = new User(

  {

name:"zxg",

age:27,

address:"100add"

}

  );

divtest.innerHTML = userObj.getname();

注意这里传入的参数的数据结构;

相关文章
相关标签/搜索