简体   繁体   English

用您自己的自定义 function 替换默认 javascript function

[英]Replacing default javascript function with your own custom function

I have a <textarea> element in a webpage that has hover, click and other events attached to it.我在网页中有一个<textarea>元素,该元素具有 hover、单击和其他附加事件。 When I add my own custom even listener to the same element for, let's say hover, it obviously executes my custom functionality but it also executes the default behavior, which is undesirable.当我将我自己的自定义甚至监听器添加到同一个元素时,比如说 hover,它显然会执行我的自定义功能,但它也会执行默认行为,这是不可取的。 I just need it to execute my piece of code and not the default one.我只需要它来执行我的一段代码,而不是默认的。

PS I am working on a chrome extension that needs to interact with this textarea. PS 我正在开发一个需要与这个文本区域交互的 chrome 扩展。 Mentioning this if it's relevant in any way.如果它以任何方式相关,请提及这一点。

Add event.preventDefault();添加event.preventDefault(); to your custom function.到您的自定义 function。 More info: https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault更多信息: https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault

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

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