javascript - 将 jQuery 事件应用到两个 DOM id 的选择器

标签 javascript jquery jquery-selectors

我有两个选择菜单(#id1 和 #id2),当验证为包含用户错误时,当与其中任何一个进行交互时,应该引发一些 DOM 更改(删除错误通知)。

再次:

var Heat_Check = jQuery('#id1' or '#id2').change(function() { ... });
PS。我知道该链没有返回值。

最佳答案

您可能想检查 change 是否是从这些选择中的任何一个触发的。尝试下面,

var Heat_Check = false;

jQuery('#id1, #id2').change(function() { Heat_Check = true; });

function heatCheck () {
   if(Heat_Check) {
      //Do your stuff
      console.log('It is hot');
   }
}

关于javascript - 将 jQuery 事件应用到两个 DOM id 的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11040273/

相关文章:

javascript - 如何将数组值传递给javascript函数? PHP Laravel

php - ajax 和 php(或其他服务器语言),哪个更好?

javascript - 使用 :not(:not()) to emulate (the hypothetical) :is() selector in jQuery

jQuery : eq() vs get()

javascript - jQuery 滞后于验证事件

javascript - Jquery查找其父表中具有属性的元素

javascript - 使用 for 循环遍历数组和 console.log 中的对象,看是否看过电影

javascript - 输入 slider ,带有动态计算的oninput

javascript - Angular 5 : Passing an array from child to parent component

javascript - 我需要从 find() 中排除 child