我使用以下代码在我的页面上查找$form
对象:
var $form = $modal.find('#modal-form');
现在我需要选择按钮。如何选择表单中的每个按钮,以便像这样对其应用筛选器?
$('button').filter(function () { })
发布于 2012-09-18 18:19:16
在$form
上下文中使用另一个find
var $form = $modal.find('#modal-form');
var $buttons = $form.find("button");
或者,使用$(selector [, context ])
var $buttons = $("button", $form);
两者都将找到给定表单的所有button
子代。
发布于 2012-09-18 18:20:08
试试这个..。
$("#modal-form button").each(function(btn){
console.log(btn);//Logs each button in the form to your console
})
发布于 2012-09-18 18:19:43
在表单元素上使用.find()
函数:
var $form = $modal.find('#modal-form');
var button = $form.find('button');
https://stackoverflow.com/questions/12474976
复制相似问题