js获取表单数据的方式,js 获取表单数据

http://www.itjxue.com  2023-01-14 18:43  来源:未知  点击次数: 

js表单提交后,如何获取表单中的数据并显示出来

表单是用form来填写,在提交前可以获取表单里面的数据。我这里用jquery实现。

html

body

????form?method='post'?action=''

????????label?for='inputText'inputText/label

????????input?type='text'?id='inputText'/

????????br/

????????label?for='checkBox1'checkBox1/label

????????input?type='checkbox'?id='checkBox1'/

????????br/

????????label?for='checkBox2'checkBox2/label

????????input?type='checkbox'?id='checkBox2'/

????????!--其他你想填写的表单选项--

????????input?type='button'?value='提交表单'?id='submitBtn'/

????/form

????script

????????$(document).ready(function()

????????{

????????????$('#submitBtn').click(function(e)

????????????{

????????????????/*一系列根据自己的意图判断输入框是否已输入内容并决定是否往下执行*/

????????????????

????????????????//获取表单的系列化数据。这会生成一个A=valueAB=valueB这种形式的字符串。

????????????????var?formData?=?$('form').serialize();

????????????????$.post('目标地址',formData,成功/失败回调函数);

????????????????e.preventDefault();

????????????});

????????????

????????});

????/script

/body

/html

js 获取整个表单

可不可以这样:

function ssubmit(){

/*

在表单提交前,不用innerHTML获取表单里面的元素。

1:获取表单里面的所有元素。

2:循环获取所有元素的输入信息,重写构成一个字符串,保存输入信息。

如:input type="text" name="textfield372" value="输入的值"/

3:处理完所有元素,将得到一个关于表单信息的长字符串,在作为隐藏字段的值。

如:长字符串

:form ..input type="text" name="textfield372" value="输入的值"/input type="text" name="textfield372" value="输入的值"/.../form

4:同时注意,这个长字符串的值需要特殊处理,如里面的双引号。。。

*/

document.form1.submit();

}

js获取表单数据(在HTML中,PHP或ASP请绕道)

Sets or retrieves the substring of the href property that follows the question mark.

Syntax

HTML N/A

Scripting object.search [ = sSearch ]

Possible Values

sSearch String that specifies or receives the substring of the href property.

The property is read/write. The property has no default value.

Expressions can be used in place of the preceding value(s), as of Microsoft? Internet Explorer 5. For more information, see About Dynamic Properties.

Remarks

The substring that follows the question mark is the query string or form data.

Example

This example function returns the search property of the current page location.

================================================

function getSearch()

{

return document.location.search;

}

================================================

js如何获取表单的值???

value

属性为

input

元素设定值,表单的值一般是元素的value属性:

假设有以下form,拥有一个input字段(带空值预定义)以及一个提交按钮

提取表单值代码:

提交之后获取的结果是:

空值:

不为空:

扩展资料:

value

属性为

input

元素设定值。对于不同的输入类型,value

属性的用法也不同:

(1)type="button",

"reset",

"submit"

-

定义按钮上的显示的文本;

(2)type="text",

"password",

"hidden"

-

定义输入字段的初始值;

(3)type="checkbox",

"radio",

"image"

-

定义与输入相关联的值;

参考资料:搜狗百科--value

js怎么获取form表单中所有的input和select

script type="text/javascript"

? // 获取指定form中的所有的inputselect对象

? function getElements(formId) {

? ? ? var form = document.getElementById(formId);

? ? ? if(form == null){

? ? ? ? ? return false;

? ? ? }

? ? ? var elements = new Array();

? ? ? var inputTagElements = form.getElementsByTagName('input');

? ? ? for (var j = 0; j inputTagElements.length; j++) {

? ? ? ? ? elements.push(inputTagElements[j]);

? ? ? }

? ? ? var selectTagElements = form.getElementsByTagName('select');

? ? ? for (var j = 0; j selectTagElements.length; j++) {

? ? ? ? ? elements.push(selectTagElements[j]);?

? ? ? }

? ? ? return elements;

? }

扩展资料:

form表单提交

在form标签中添加Action(提交的地址)和method(post),且有一个submit按钮。

(input type='submit')就可以进行数据的提交,每一个input标签都需要有一个name属性,才能进行提交。

当点击登陆时,向数据库发生的数据是:username=usernamepassword=password.

这种默认的提交方式,一般会进行页面的跳转(不成功时跳转到当前页面)。而有时候是对弹出框进行数据提交的,希望提交成功则关闭弹出框并刷选父页面,失败则提示失败原因,且弹出框不关闭。此时可以采用Ajax进行数据提交。

js获取form表单提交的数据?

用下面的函数可以获取:

function getUrlParam(name) {

var reg = new RegExp("(^|)" + name + "=([^]*)(|$)", "i");

var r = window.location.search.substr(1).match(reg);

if (r != null) return decodeURI(r[2]);

return null;

}

如获取user,执行getUrlParam("user")就可以了

(责任编辑:IT教学网)

更多

推荐杀毒防毒文章