时间:2021-07-01 10:21:17 帮助过:32人阅读
实验的代码如下:
<!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
以上就是html form 向jiavascript传值实例的详细内容,更多请关注Gxl网其它相关文章!