【问题标题】:jQuery reference to the form that triggered the calljQuery 对触发调用的表单的引用
【发布时间】:2014-07-29 01:24:43
【问题描述】:

我正在与jQuery$.post() 合作。

我有以下代码:

$('#form #buttonQuery').click(function () {
    var post = $.post(url, info,process, 'json');
}

如何在函数内部引用表单的actionname

我试过$(this).action,但它不起作用。

谢谢

【问题讨论】:

  • 页面上应该只有唯一的 ID。你只需要$('#buttonQuery')… 如果你有多个具有相同ID的元素,那么你做错了

标签: javascript jquery forms post


【解决方案1】:

任何表单元素都有对表单的内置本地引用,它是this.form

$('#buttonQuery').on('click', function () {

    var action = $(this.form).attr('action'); // jQuery

    var name = this.form.name; // native property

    var post = $.post(url, info, process, 'json');
});

在 jQuery 中你也可以使用$(this).closest('form');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多