排除序列化中的某些输入 [英] Excluding certain inputs on serialize

查看:88
本文介绍了排除序列化中的某些输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按名称排除输入(这是隐藏我的随机数的隐藏输入)

I am trying to exclude an input by name (it is a hidden input holding my nonce)

以下问题几乎是我要寻找的:

The following question is almost what I am looking for:

如何使用jQuery的表单.序列化但排除空字段

但是我对解决方案有2个问题-指出要序列化表单数据,但空输入和值=."的输入除外.

but I have 2 questions about the solution there- which states that to serialize form data except for empty inputs and inputs where the value = "."

$("#myForm :input[value][value!='.']").serialize();

首先,我无法使其与jquery变量"this"一起使用

first of all, i can't get it to work with the jquery variable "this"

$('#ofform').live('submit', function(e) {
    e.preventDefault();
    var serializedReturn = $(this :input[name!='security']).serialize();        
});

其次,我有一个单独的表单,其ID为ofform-reset,如果我使用的话:

And secondly I have a seperate form with the id of ofform-reset and if i use:

var serializedReturn = $(#ofform :input[name!='security']).serialize(); 

它以另一种#ofform-reset形式拾取输入,这些输入与AND/OR输入不包含在标记内.

it picks up the inputs in the other #ofform-reset form, AND/OR inputs that aren't enclosed within a tag.

找到了我以前的一个问题的答案.样式的无效标记:

found the answer in one of my previous questions. invalid markup of the style:

<form id="ofform">
 <div id="toolbar">
 <button id="save">Save</button>
</form>
<form id="ofform-reset">
 <button id="reset">Reset</button>
</form>
</div>

现在要弄清楚如何使用2个不同的按钮来控制相同的表单

now to figure out how to use 2 different buttons to control the same form

推荐答案

您不需要:,因为input是一个元素,而不是伪选择器.其次,您不能在选择器中使用像这样的对象和文本字符串.相反,您需要提供此值作为$()的作用域参数:

You don't need the :, because input is an element not a pseudo selector. Secondly you cannot use an object and a text string like that in your selector. You instead need to supply this as the scope argument to $():

$('#ofform').live('submit', function(e) {
    e.preventDefault();
    var serializedReturn = $('input[name!=security]', this).serialize();        
});

这篇关于排除序列化中的某些输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆