I've an input field that can be modify by users and js buttons. I need to throw an event when the user writes/deletes something in the textarea and when a button modifies the value of the input without using jQuery.

我有一个输入字段,可以由用户和js按钮修改。当用户在textarea中写入/删除某些内容时,以及当一个按钮在不使用jQuery的情况下修改输入值时,我需要抛出一个事件。

I tried to overwrite input's get and set methods but when I change input text with js before modify it by my hand and change it again with js the displayed text in the input box doesn't change.

我试图覆盖输入的get和set方法但是当我用js更改输入文本然后用我的手修改它并用js再次更改它时输入框中显示的文本不会改变。

It has to work on IE11 and Chrome (cannot use onpropertychange event).

它必须适用于IE11和Chrome(不能使用onpropertychange事件)。

I'm sorry for my bad english but I hope I was clear.

我很抱歉我的英语不好但我希望我很清楚。

`https://jsfiddle.net/gzmdc3zz/1/`

1 个解决方案

#1


0

Well there is an 'oninput' and an 'onchange' in javascript. Try one of these:

好吧,javascript中有'oninput'和'onchange'。尝试以下方法之一:

object.oninput=function(){myScript};

Edit: I think there is no true solution for this, but you can try the hack on this link instead of your manipulated setters/getters. In this case you get an event-callback whenever the given property of an element has changed programmatically (with new and old value).

编辑:我认为没有真正的解决方案,但你可以尝试在这个链接上的黑客而不是你操纵的setter / getters。在这种情况下,只要元素的给定属性以编程方式更改(使用新旧值),就会获得事件回调。

You can then change the value on the original element by yourself or do whatever you want. In addition you then need a normal .oninput-event on the element,too. To get the event from user inputs.

然后,您可以自己更改原始元素的值或执行您想要的任何操作。此外,您还需要在元素上使用正常的.oninput事件。从用户输入获取事件。

If anyone has a better idea how to manage this, I'm looking forward to read it.

如果有人知道如何管理这个,我期待着阅读它。

更多相关文章

  1. 在关联数组中移动元素[重复]
  2. 切换元素类并使用旧类在视图中添加新元素
  3. 在AngularJS中轻松控制dom - 单击按钮,然后将焦点设置为输入元素
  4. 如何在详细信息标记的结束事件上添加CSS转换?
  5. 如何设置动画以使元素围绕圆圈移动?
  6. jQuery选择器,用于查找与选择器匹配的给定元素之后的第一个元素
  7. 动态定位Bootstrap工具提示(用于动态生成的元素)
  8. 无法从按钮onclick事件ASP.NET 4调用Javascript函数
  9. js获取点击事件的位置,兼容主流浏览器

随机推荐

  1. 【Android学习】数据传递三种方式
  2. 说说Android的广播(4) - 前台广播为什么
  3. Android Studio 常见异常解决办法
  4. Android——性能优化相关文章
  5. Linux下 使用Repo和Git下载Android源代码
  6. Eclipse默认标签TODO,XXX,FIXME和自定义
  7. android 命令修改时间或程序修改系统时间
  8. 让Android 设备通过USB 转RJ45有线网卡上
  9. Android中ListView的性能问题
  10. Android Launcher 设置壁纸