How to get form tag value in jquery

(*-*)浩
Release: 2019-05-22 20:46:11
Original
3152 people have browsed it

In the daily development process, there are many places where forms are used. For example, login, registration, payment, order filling, backend management, etc.

How to get form tag value in jquery

#It is a common practice to use jQuery to get the value of the form.

Common forms

Single line text field:

Copy after login

Password field:

Copy after login

Single choice:MaleFemale

   
Copy after login

Multiple selection:

篮球 足球 皮球
Copy after login

Drop-down list:

Copy after login

Multi-line text field:

Copy after login

Use jQuery to get the form tag value

// 昵称 var name = $("#name").val(); console.log(name); // 密码 var pass = $("#pass").val(); console.log(pass); // 性别 var sex = $("input:radio:checked").val(); console.log(sex); // 性别 var sex1 = checkAll($("input:radio")); console.log(sex1); // 兴趣 var hobby = checkAll($("input:checkbox")); console.log(hobby); // 城市 var city = $("#city").val(); console.log(city); // 城市 var city1 = $("#city option:selected").val(); console.log(city1); // 备注 var remark = $("#remark").val(); console.log(remark);
Copy after login

A function that can get single and multiple selections, returning an array of values:

//获取单选或者多选的值,返回一个值得数组,如果没有值,返回空数组,参数inputlist是jQuery对象 function checkAll(inputlist){ var arr = []; var num = inputlist.length; for(var i = 0; i < num; i++){ if(inputlist.eq(i).is(":checked")){ arr.push(inputlist.eq(i).val()); } } return arr; }
Copy after login

Summary:

Single line text: $("#text").val();

Password: $("#pass").val();

Single selection: $ ("input:radio:checked").val();

Multiple selection: traverse $("input:checkbox") to determine whether it is selected

Drop-down: $("#select" ).val(); or $("#select option:select").val();

Multi-line text: $("textarea").val();

The above is the detailed content of How to get form tag value in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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 admin@php.cn
Popular Recommendations
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!