我正在研究一种通过jQuery检测输入域中的值变化的智能方法--也就是最灵活、最稳定的方法。
到目前为止,我想出了这个已经适合我的需求。但我想知道这种方法是否有一些警告。我是不是漏掉了什么?
jQuery(document).ready(function($) { // wait till page is loaded
$('form :input').on("input", function() { // listen on all input fields on all forms
form_name = $(this).parents("form").attr("name"); // gives id of form
form_id = $(this).parents("form").attr("id"); // gives name of form
input_name = this.name; // gives name of input field
input_id = this.id; // gives id of input field
input_value = this.value; // gives value of input field
if (form_name == 'whatever' &&
input_name == 'email' &&
input_value == 'dummy@domain.com') alert('ok'); // do whatever you want
});
});发布于 2020-07-29 17:37:43
您可以通过以下代码获取表单中的所有输入
$('form :input').each(function () {
$(this).on("change", function () {
//your code
});
});https://stackoverflow.com/questions/63150550
复制相似问题