开发者

Jquery: How to get the value of an input and put in an array

开发者 https://www.devze.com 2023-01-05 19:39 出处:网络
I have an input <input type=\"text\"开发者_如何转开发 value=\"hello\" /> and I want to get the value of this and using Jquery, save the value in an array.

I have an input

<input type="text"开发者_如何转开发 value="hello" />

and I want to get the value of this and using Jquery, save the value in an array.

How can I do this???


using jQuery,

$(document).ready(function(){
   var arr = [];
   arr.push($('#inputID').val());
})

you should give your input an id

<input type="text" value="hello" id="inputID" />


you could run this code for submitting:

$('formname').submit(function() {
  alert($(this).serialize());
  return false;
});

This would return a string like:

a=1

You could then save this to an array.


var formValues = $('#your_form').serialize();
var formValuesAsArray = $('#your_form').serializeArray();

To get the value from your input, you should give it a name attribute; for example <input type="text" name="message" /> and get its value by $('input[name=message]').val()

0

精彩评论

暂无评论...
验证码 换一张
取 消