Home > Web Front-end > JS Tutorial > body text

js获取form的方法_javascript技巧

WBOY
Release: 2016-05-16 16:00:39
Original
2039 people have browsed it

本文实例讲述了js获取form的方法。分享给大家供大家参考。具体如下:

先来看下面代码:

 
 
 
window.onload=function(){ 
   var f1=document.f1; 
   var f2=document.forms[1]; 
 alert(f2.id); 
  var f3=document.forms['f1']; 
} 
 

Copy after login

操作表单:

 
  
  
 


Copy after login

js操作form的三种方式:

1. 利用表单在文档中的索引或表单的name属性来引用表单

复制代码 代码如下:
document.forms[i]  //得到页面中的第i个表单
document.forms[fromName] //得到页面中相应name的表单

2. 利用表单的id属性

复制代码 代码如下:
document.getElementById(formId);

3.

复制代码 代码如下:
document.formName;//最为常用的一种方式

希望本文所述对大家的javascript程序设计有所帮助。

Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!