简体   繁体   English

如果在不触摸此输入的情况下从另一个元素插入值,如何处理输入类型为“ text”的输入的更改或输入事件

[英]How to handle change or input event of input type=“text” if value is inserted from another element without touching this input

I have a input type="text" and next to that a button which opens up a calendar on click. 我有一个输入type =“ text”,旁边有一个按钮,单击后可打开日历。 When a value is selected in calendar textbox ix populated. 在日历文本框ix中选择一个值时,将进行填充。

I would like to handle on change of textbox to enable other controls. 我想处理文本框的更改以启用其他控件。

change, input etc events are triggered only if use manually enters values in the text box. 仅当使用手动在文本框中输入值时,才会触发更改,输入等事件。 But in my case I am not touching the input textbox. 但就我而言,我没有触摸输入文本框。

Thanks. 谢谢。

Use jquery change event. 使用jQuery更改事件。

$("input").change(function(){
  //do something
})

Update: 更新:

As .change event doesn't get fired when you change value using any javascript method, there is a work around. 由于使用任何javascript方法更改值时不会触发.change事件,因此可以解决。

When you change the date, you can trigger an event to the input element like $("input").keyup() and listen using: 更改日期时,可以触发输入元素(例如$("input").keyup()并使用以下命令进行监听:

$("input").keyup(function(){
    // input updated
  })

codepen example: https://codepen.io/azharuddinkhan8898/pen/MNrLad codepen示例: https ://codepen.io/azharuddinkhan8898/pen/MNrLad

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

相关问题 如何在没有窗口刷新的情况下在值更改时捕获输入类型“文本”上的事件? - How to catch the event on input type 'text' on value change without the window refresh? 如何改变 <input type=“text”> 按属性值 - How to change <input type=“text”> value by attribute 如何通过单击复选框将文本元素从输入复制到另一个输入? - How to copy text element from input into another input by clicking on a checkbox? 如何从VueJS中的另一个输入更改输入值 - How to change value of input from another input in VueJS 如何处理输入类型文件的取消事件? - How to handle cancel event of input type file? 如何处理 jPrompt 输入的更改事件? - How to handle change event for jPrompt input? 拖放到输入元素时获取值更改事件 - Get value change event on drop to input element 使用 javascript 中的输入“type=text”元素将值从一页传递到另一页 - passing value from one page to another using input "type=text" element in javascript 使用js设置输入元素值时如何触发更改事件 - How to trigger change event when set input element value with js 如何正确捕获动态插入的“输入”文本元素的onchange或onkeyup事件? - How do I properly capture an onchange or onkeyup event for a dynamically inserted 'input' text element?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM