2

Jquery 允许通过以下方式提交表单:

$('#target').submit();

有没有办法知道触发按钮当前的形式?

我需要的是模拟正常提交按钮的行为

<button type="submit">Send</input>

经过

<button type="button" onclick="jquery_function_that_submits_the_current_form">Send</input>
4

3 回答 3

2

说明性演示:http: //jsfiddle.net/QWdqt/1/

HTML

<form action="first">
    <button>1</button>
</form><form action="second">
    <div>
        <button>2</button>
    </div>
</form>

jQuery

$('button').click(function() {
    alert($(this).parents('form').attr('action'));
});

当然,在您的示例中,您可以将其更改alert()为:

$('button').click(function() {
    $(this).parents('form').submit();
});
于 2013-09-10T10:07:39.593 回答
1
$('button').on('click', function() {
    var currentForm = $(this).closest('form');
    currentForm.submit();
});
于 2013-09-10T10:08:54.897 回答
0

工作演示

代码

function submitform(button)
{
    button.form.submit();
}

html

<button type="button" onclick="submitform(this);">Send</button>

另一种方法

只是这个

<button type="button" onclick=" this.form.submit();">Send</button>
于 2013-09-10T10:06:29.773 回答