<!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>js测试</title> </head> <body> <form name="form1" action="test1.html" method="post"> <input type="text" name="username" value="zhang"/> <input type="button" name="ok" value="保存1"/> </form> <form name="form2" action="test2.html" method="post"> <input type="text" name="username" value="zhang2"/> <input type="button" name="ok2" value="保存2"/> </form> <script language="javascript"> //使用两种方式输出表单的action值/method值(使用表单的名称,使用表单数组forms) //方法1 var formElement=document.form1; alert(formElement.action); alert(formElement.method); //方法2 var formElement=document.forms[0]; alert(formElement.action); alert(formElement.method); </script> </body> </html>
<!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>js测试</title> </head> <body> <form name="form1" action="" method="post"> 患者姓名<input type="text" name="username" value="zhang"/> <input type="button" name="ok" value="打印患者信息" onclick="printPerson()"/> <input type="button" name="ok2" value="查询患者信息" onclick="selectPerson()"/> </form> <script language="javascript"> //通过javaScript函数方式访问printPerson.html和selectPerson.html function printPerson(){ var forElement=document.forms[0]; forElement.action="printPerson.html"; forElement.method="post"; forElement.submit(); } function selectPerson(){ var forElement=document.forms[0]; forElement.action="selectPerson.html"; forElement.method="get"; forElement.submit(); } </script> </body> </html>
function print(msg){ document.write(msg); }
<!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>js测试</title> </head> <body> <script language="javascript"> //方法1 //使用普通方法 function add1(a,b){ return a+b; } alert(add1(1,2)); //方法2 //构造函数方式定义javascript函数 var add2=new Function('a','b','return a+b'); alert(add2(3,4)); //方法3 //使用函数直接量的方式定义函数 var add3=function(a,b){ return a+b; } alert(add3(5,6)); </script> </body> </html>
以上就是Js的基础知识的大致回顾
转载请注明出处:http://blog.csdn.net/acmman/article/details/47806539