05-javascript基础回顾


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form name="form1" action="test.html" method="post">
		<input type="text" name="username" value="zhang">
		<input type="button" name="ok" value="保存1">
	</form>
	
		<form name="form2" action="test1.html" method="post">
		<input type="text" name="username" value="zhang2">
		<input type="button" name="ok" value="保存2">
	</form>
</body>
<script type="text/javascript">
	//使用俩种方式输出表单的action值(使用表单的名称,使用表单数组forms)
	//方法一
	var formElement=document.form1;
	alert(formElement.action);
	alert(formElement.method);
	//方法二
	alert(document.forms[0].action);
	alert(document.forms[0].method);
</script>
</html>

javascript中定义函数的三种方式

第一种方式---正常方式

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form name="form1" action="" method="post">
		患者姓名:<input type="text" name="username" value="zhang"/>
		<input type="button" name="ok" value="打印患者信息" οnclick="printPerson();"/>
		<input type="button" name="ok" value="查询患者信息" οnclick="selectPerson();"/>
	</form>
</body>
<script type="text/javascript">
	//第一种定义函数的方法,正常方法
	//通过JavaScript函数的方式访问printPerson.html和selectPerson.html
	function printPerson(){
		var formElement=document.forms[0];
		formElement.action="printPerson.html";
		formElement.method="post";
		formElement.submit();
	}
	function selectPerson(){
		var formElement=document.forms[0];
		formElement.action="selectPerson.html";
		formElement.method="get";
		formElement.submit();
	}
</script>
</html>

第二种方式---构造函数的方式(不常用)

//使用构造函数方法定义javascript函数
	var add=new Function('a','b','return a+b;');
	alert(add(3,4));

第三种方式---函数直接量定义函数(常用)

//匿名函数
	var add=function(a,b){
		return a+b;
	}	
	alert(add(3,4));



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

会编程的阿强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值