<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP ‘test3.jsp‘ starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script src="js/jquery-2.1.1.min.js"></script>
<script>
var obj={}; //实例化对象
obj.name="张三"; //属性赋值
obj[‘age‘]=21; //赋值的时候.和[]都是可以的,但是一定要加上引号
obj.getName=function(){
alert(this.name);
}
//obj.getName();
//使用delete可以删除对象的属性方法
delete obj.name;
// alert(obj.name); //undefined
//遍历js对象 for in语句格式
for(var attribute in obj){
//alert(attribute+‘=‘+obj[attribute]); //遍历对象用[]不要用.,会出现undefined
}
//constructor保存对象的创建函数
//alert(obj.constructor);
//hasOwnProperty(property)判断所给属性在对象中是否存在
//alert(obj.hasOwnProperty(‘age‘)); //一定要加上引号
alert(obj.propertyIsEnumerable(‘age‘)); //判断属性是否可以for in 枚举出来
</script>
</head>
<body>
This is my JSP page. <br>
</body>
</html>本文出自 “matengbing” 博客,请务必保留此出处http://matengbing.blog.51cto.com/11395502/1878718
原文地址:http://matengbing.blog.51cto.com/11395502/1878718