I'm using jQuery. I have a disabled textarea: <textarea id="textarea" disabled="disabled"></textarea>. I want to make it so that when a user clicks on the textarea, it will do something, such as an alert box. So, I have $('#textarea').click(function() { alert('Test'); });.

我正在使用jQuery。我有一个禁用的textarea:

However, this only works when the textarea is not disabled. So, how can I make the click event fire even when the textarea is disabled?

但是,这仅在未禁用textarea时有效。那么,即使禁用textarea,如何才能使click事件触发?

5 个解决方案

#1


4

Instead of disabling it, you could either try simulating the disabled behaviour with CSS and continue receiving mouse events from it.

您可以尝试使用CSS模拟禁用的行为,并继续从中接收鼠标事件,而不是禁用它。

Or see this answer Event on a disabled input where Andy E shows how you can place an invisible element (an overlay) on top of the input for receiving those mouse events when the input is disabled.

或者在禁用输入上查看此答案事件,其中Andy E显示如何在输入顶部放置一个不可见元素(覆盖),以便在禁用输入时接收这些鼠标事件。

He removes the overlay and enables the input when it is clicked, but you could change the behavior to anything you'd like.

他删除叠加层并在单击时启用输入,但您可以将行为更改为您想要的任何内容。

更多相关文章

  1. js“DOM事件”之鼠标事件、js的测试方法、js代码的放置位置
  2. 单击元素后的load()特定href
  3. 使用angularjs添加包含事件的新标记
  4. jqGrid 数据加载完事件 loadComplete 使用
  5. JavaScript - 检测click事件是否触发了DOMNodeInserted事件
  6. Jquery中动态添加元素的绑定事件不起作用
  7. 将div停靠在窗口左侧并再次单击原始位置
  8. 从列表单击功能获取列表项的值
  9. 我可以使用onBlur事件对TextBox进行日期检查吗?

随机推荐

  1. Android 面试必备 - 线程
  2. Android中实现全屏、无标题栏的两种办法(
  3. Android 远程调试 JNI 实现 ( Android JNI
  4. 【Android(安卓)Developers Training】 5
  5. [Android] Android中将一个图片切割成多
  6. 再次研究Android MediaPlayer
  7. 布局指令大全
  8. Android(安卓)学习 之 Looper Handler Th
  9. android基本功
  10. Android中的Parcel机制 实现Bundle传递对