Javascript 创建对象及为对象属性赋值

来源:互联网 发布:彩票源码论坛php 编辑:程序博客网 时间:2024/05/17 06:58

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <label>
 <input type="text" id="txtName" name="textfield" value="ss" />
 <input type="text" id="txtAdd" name="textfield" />
 <input type="text" id="txtxingbie" name="textfield" />
 <input type="text" id="txtAge" name="textfield" />   
  </label>
  <label>
   <input type="submit" name="Submit" value="提交" onclick="btn_OK" />
   <INPUT name=Submit type=submit class=button  action="http://www.baidu.com" onClick="MM_openBrWindow()" value="登 陆">
  </label>
 
  <script type="text/javascript">
   
  function MM_openBrWindow() { //v2.0
   //window.open(theURL,winName,features);
   //alert("JavaScript");
   var strName = document.getElementById("txtName").value;
   var strAdd = document.getElementById("txtAdd").value;
   var strXB =  document.getElementById("txtxingbie").value;
   var strAge = document.getElementById("txtAge").value;


   alert(strName);

   personObj = new Object()
   personObj.Name = strName
   personObj.Add = strAdd
   personObj.XB = strXB
   personObj.Age = strAge   

   
   alert(personObj.Name);
       alert(personObj.Add);
   
   //For (var prop in personObj)
   // alert(prop+="+this[prop]+"");
  }
   
  </script>
</form>
</body>
</html>

原创粉丝点击