html form 向jiavascript传值

实验的代码如下:

<!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">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>你好</title>

</head>

<script language="javascript">

function sub(a,b){

alert(a.value);

        alert(b.value);

}

</script>

   

<body>

<form action="sub" method="post"  name="myForm">

  <p>First name: <input type="text" id=test1 name="fname" /></p>

  <input type="button" value="Submit" onclick="sub(this,document.myForm.fname)" />

</form>

</body>

</html>

总结:

onclick="sub(this,document.myForm.fname)" 中的this是返回按钮的id

你可能感兴趣的:(JavaScript,form,传值)