日期:2014-05-16 浏览次数:20412 次
<%@ 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 'js12.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 type="text/javascript">
//alert(Math.PI);
var obj = new Object();
//alert(obj.username);
obj.username = "曹欢";//维obj对象增加一个属性
//alert(obj.propertyIsEnumerable("username"));
//alert(obj.username);
delete obj.username;
//alert(obj.username);
//在javascript中可以动态的增加、删除属性
//在javascript中常见的定义对象的方法
var object = {name:"曹欢",age:21,sex:"男"};
//alert(object.age);
delete object.age;//删除对象中的属性
//alert(object.age);
//定义数组的方法
var arr = new Array();
arr.push(1);
arr.push(2);
arr.push(3);
//alert(arr.length);
var arr1 = [1,2,3];
//alert(arr1.length);
//关于数组的排序
var arr2 = [1,3,24];
//alert(arr2.sort());//顺序是1,24,3//排序是首先将要排序的元素转化成字符串(原因是数组里可以放不同类型的数据),然后在按照字符串来排序。
function compareasd(num, num1)
{
var a = parseInt(num);
var b = parseInt(num1);
if(a < b)
{
return -1;
}
else if(a == b)
{
return 0;
}
else
{
return 1;
}
}
//alert(arr2.sort(compareasd))//compareasd是函数名,是对函数名的引用
//匿名函数
var arr3 = [3, 12,5];
//alert(arr3);
/*arr3.sort(function(num, num1)//匿名函数
{
var a = parseInt(num);
var b = parseInt(num1);
if(a < b)
{
return -1;
}
else if(a == b)
{
return 0;
}
else
{
&nbs