<!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" xml:lang="zh-cn"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title>网页标题</title> <meta name="keywords" content="关键字列表" /> <meta name="description" content="网页描述" /> <link rel="stylesheet" type="text/css" href="" /> <style type="text/css"></style> <script type="text/javascript"> //定义一个对象 var obj = new Object(); //增加属性 obj.name = ‘张三‘; obj.sex = ‘男‘; obj.age = 25; obj.isMarried = true; obj.edu = ‘大专‘; obj.school; //增加方法 obj.showInfo = function (){ var str =‘<h2>‘+obj.name+‘的个人信息</h2>‘; str +=‘姓名:‘+obj.name; str +=‘<br/>性别:‘+obj.sex; str +=‘<br/>年龄:‘+obj.age; str +=‘<br/>婚否:‘+(obj.isMarried ?‘已婚‘: ‘未婚‘); str +=‘<br> 学历:‘+obj.edu; str +=‘<br/>学校:‘+(obj.school ? obj.school:‘未定义‘); return str; } document.write(obj.showInfo()); //用大括号{}创建对象 var obj={ name : ‘张三‘, sex : ‘男‘, age : 34, isMarried : true, edu : ‘大专‘, school : undefined, showInfo: function(){ var str =‘<h2>‘+obj.name+‘的个人信息</h2>‘; str +=‘姓名:‘+obj.name; str +=‘<br/>性别:‘+obj.sex; str +=‘<br/>年龄:‘+obj.age; str +=‘<br/>婚否:‘+(obj.isMarried ?‘已婚‘: ‘未婚‘); str +=‘<br> 学历:‘+obj.edu; str +=‘<br/>学校:‘+(obj.school ? obj.school:‘未定义‘); return str; } } document.write(obj.showInfo()); </script> </head> <body> </body> </html>
<!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" xml:lang="zh-cn"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title>网页标题</title> <meta name="keywords" content="关键字列表" /> <meta name="description" content="网页描述" /> <link rel="stylesheet" type="text/css" href="" /> <style type="text/css"></style> <script type="text/javascript"> //定义一个数组 var arr =[4,5,0,34,67,2]; //定义一个函数 function getMax(arr1){ //假设一个最大值 var max=arr1[0]; for(var i=0;i<arr1.length;i++){ if(max<arr1[i]){ max = arr1[i]; } } document.write( max); } getMax(arr); </script> </head> <body> </body> </html>
时间: 2024-10-17 13:00:39