2011-02-02 112 views
0

我有幾個表格,編號爲comment_addXXX。我想立即提交所有這些信息,而不是單獨提交每個表單。jquery表單提交

即我可以簡化類似:

$('#comment_add1111').submit(); 
$('#comment_add111122').submit(); 
$('#comment_add1222111').submit(); 
$('#comment_add11133331').submit(); 

成類似:

$('#comment_add*').submit(); 

回答

0

或示例,考慮HTML: 例子:

<form id="target" action="destination.html"> 
    <input type="text" value="Hello there" /> 
    <input type="submit" value="Go" /> 
</form> 
<div id="other"> 
    Trigger the handler 
</div> 

事件處理程序可以必須採用以下格式:

$('#target').submit(function() { 
    alert('Handler for .submit() called.'); 
    return false; 
}); 

其他控件的ID:

$('#other').click(function() { 
    $('#target').submit(); 
}); 
0

是不是引號必要,佩塔提克瓦?

$('form[id^="comment_add"]').each(function() { 
    $(this).submit(); 
});