简体   繁体   English

文档输入轨道更改

[英]document Input track change

I need help on this one: 我需要这方面的帮助:

In the document there are several input fields with <div class="quantity"><input .. > This is automatically generated by the system and i have no access to alter this. 在文档中有几个输入字段<div class="quantity"><input .. >这是由系统自动生成的,我没有权限改变它。

So i need a way with jquery to track the onchange function when the input changes.. 因此,当输入发生变化时,我需要一种使用jquery来跟踪onchange函数的方法。

What is a good way to achieve this??? 有什么好办法实现这个???

var updateInput = document.getElementById(".quantity input"); var updateInput = document.getElementById(“。quantity input”);

if ( updateInput ????? ) { 
      alert("Hallo") 
};

Thank for your guidance!! 谢谢你的指导!!

getElementById does not work on class names. getElementById不适用于类名。 You asked for jquery, why not use change() ? 你问过jquery,为什么不使用change()

$('.quantity input').change(function() {
    alert('Input changed');
});

From the manual: 从手册:

The change event is sent to an element when its value changes. 更改事件在其值更改时发送到元素。 This event is limited to <input> elements, <textarea> boxes and <select> elements. 此事件仅限于<input>元素, <textarea>框和<select>元素。 For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus. 对于选择框,复选框和单选按钮,当用户使用鼠标进行选择时会立即触发事件,但对于其他元素类型,事件将延迟,直到元素失去焦点。

Demo: http://jsfiddle.net/Madmartigan/yzGYU/ 演示: http//jsfiddle.net/Madmartigan/yzGYU/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM