本文介绍了单击提交按钮的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这应该很简单.
我正在检查是否正在使用jquery提交表单.表单具有多个带有不同值的提交按钮:
I'm checking if a form is being submitted using jquery. The form has multiple submit buttons with various values:
<button type="submit" value="foo">Foo</button>
<button type="submit" value="bar">Bar</button>
我想找到刚刚提交表单的按钮的值:
I would like to find the value of the button that just submitted the form:
$(form).live('submit', function() {
// Get value of submit button
}
谢谢
推荐答案
绑定该事件以提交按钮而不是表单,然后$(this)将引用按钮...
Bind the event to submit buttons instead of the form and then $(this) would have the reference to the buttons...
$(":submit").live('click', function() {
alert($(this).val());
})
编辑:自jQuery 1.7起,不推荐使用 live . 改用上.
EDIT As of jQuery 1.7 live is deprecated. Use on instead.
$(document).on("click", ":submit", function(e){
alert($(this).val());
});
这篇关于单击提交按钮的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!