使用jQuery查找表单内所有输入元素的最佳方法 [英] Best way to find all input elements inside a form using jQuery

查看:164
本文介绍了使用jQuery查找表单内所有输入元素的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在表单内找到所有表单元素,并在值的变化时触发标志。目前我正在使用以下方法。我不确定这是否有效。但它肯定适用于: .find('input [type = text])

I need to find all form elements inside inside a form and trigger a flag on change in the value. Currently I am using the method below. I am not sure if this works or not. But It surely works for: .find('input[type=text])

$('#form').find('input[type=text], input[type=radio], input[type=checkbox], select, textarea').each(function(){
  $(this).change(function(){
    if( change !== 1 ) change = 1;
  });
})

现在我用逗号添加了多个元素。这是否有效,这是最好的方法。

Now I have added multiple elements with the comma. Will this work and is this the best way to do this.

感谢所有帮助。

谢谢!

推荐答案

试试这个:

$('#form').find(':input').each(function(){
  $(this).change(function(){
    if( change !== 1 ) change = 1;
  });
})

检查文档@:


http://api.jquery.com/input-selector/

这篇关于使用jQuery查找表单内所有输入元素的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆