开发者

jquery serializearray - how to remove 3 elements or how to make them different

开发者 https://www.devze.com 2023-03-09 05:53 出处:网络
I\'m using the serializearray with success, but now I need to make a trick. How can I build this array, but defining that some inputs must have a specific class, so I 开发者_如何学运维can make difere

I'm using the serializearray with success, but now I need to make a trick.

How can I build this array, but defining that some inputs must have a specific class, so I 开发者_如何学运维can make diferent sql queryes based on that?

this is what I'm now using

$.each($("form[name='admin']").serializeArray(), function(i, campo)

I need it like that, but also need to add something to compare, per example

if(something) {
    $sql_query = 'select * from admin';
} else {
    $sql = 'select * from teste';
}


Use .map() and filter the collection based on your own requirements, then call serialize.

$('#myForm :input').map(function(i,e){
  // test against e, return the object if it's
  // a good fit, otherwise return null
  var $e = $(e);
  return ($e.hasClass('foo') ? $e : null);
}).searializeArray();


You can do something like the following. Chances are you don't need to use .serializeArray because you want to pass the values through a POST request:

var postString = $('form[name='admin'] input.classToFind').serialize();
0

精彩评论

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