0

我试图编写一个发生在页面中所有表单上的函数:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
    $('form').click(function() {
        alert (this.serialize());
        return false;
    });
</script>

但我得到了错误

this.serialize 不是函数

我究竟做错了什么?

更新

$(this)工作过

所以现在我尝试了:

$('form').click(function() {
    alert ($(this).serialize());
    $("input, select, textarea").attr("disabled", true);
    alert ($(this).serialize());
    return false;
});

但这会禁用页面上所有表单中的所有元素。

我怎样才能禁用提交按钮被按下的表单中的那些?

4

3 回答 3

1

尝试

$(this).serialize();

代替

this.serialize();

要仅禁用此表单的字段,

$('form').click(function () {

    // ...

    $(this).find('input, select, textarea').each(function () {
        $(this).prop('disabled', true);
    });

    // ...

});
于 2013-10-01T01:42:43.343 回答
0

您需要使用 jQuery 对象:$(this).serialize()

于 2013-10-01T01:42:22.757 回答
0

我正在回答你关于残疾人的第二个问题。

如果您愿意,可以执行以下操作:

$('#saveButtonForm3').click(function() {
    alert ($(this).parent().serialize());  // parent() is the form, $(this) is the button
    // this line will disable the fields in the form where the save button is clicked
    $(this).parent().find("input, select, textarea").attr("disabled", true);
    alert ($(this).parent().serialize());
    return false;
});
于 2013-10-01T02:10:26.040 回答