简体   繁体   中英

How to get all the form elements values using name attribute

I am trying to access the form elements in a jsp page using the name attribute. this form contains text,textarea and select fields. now in my javascript file i have to get these values.

$("input[name=first_name]").val() 

By using this we can get only values of input type fields (for ex:text) and not and fields.

Please help me to resolve this.i want to use jquery code for this.

You could use the :input selector:

$(':input[name="first_name"]').val()

Also note that having multiple form elements (text fields, textareas, select boxes) with the same name is probably wrong.

您在选择器中不需要元素的类型:

$("[name=other_name]").val() 

您应该使用:input选择器

Use

var form = $("#form_id");
//form['name_of_input_field']

this is much quicker than using selectors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM