javascript获取表单值的7种方式
见代码:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>表单对象--获取表单值的7种方式</title> </head> <body> <form action="" name="myform"> <input type="text" name="user" value="admin"> </form> <script> document.write(document.myform.user.value+"1<br/>"); document.write(document['myform'].user.value+"2<br/>"); document.write(document.forms.myform.user.value+"3<br/>"); document.write(document.forms[0].user.value+"5<br/>"); document.write(document.forms['myform'].user.value+"4<br/>"); document.write(document.forms.item(0).user.value+"6<br/>"); document.write(document.forms.item('myform').user.value+"7<br/>");//FF可能不支持 </script> </body> </html>
推荐使用
document.write(document.myform.user.value);
(本文完)
本文优先在公众号"飞鸿影的博客(fhyblog)"发布,欢迎关注公众号及时获取最新文章推送!
本文优先在公众号"飞鸿影的博客(fhyblog)"发布,欢迎关注公众号及时获取最新文章推送!
作者:飞鸿影
出处:http://52fhy.cnblogs.com/
版权申明:没有标明转载或特殊申明均为作者原创。本文采用以下协议进行授权,自由转载 - 非商用 - 非衍生 - 保持署名 | Creative Commons BY-NC-ND 3.0,转载请注明作者及出处。