Coffeescript:如何在更改后检索元素内容

Coffeescript: How to retrieve element content after it has changed

这可能是一个相当初级的 Coffeescript 问题:我想在更改后检索文本框元素的内容。我尝试了以下方法:

$("#notes").change (e) ->
  alert("Note content changed. Is now " + $("#notes").text())

其中 "notes" 是文本框的 ID。

这不起作用。它始终显示 "notes" 文本框的原始内容。我怀疑这是因为 coffeescript 在加载时被编译为 javascript。

我想用 Coffeescript 做些什么?如果是这样,请告诉我。

谢谢。

您以错误的方式从 textarea 读取值。

没有jQuery:

$("#notes").change (e) ->
  alert("Note content changed. Is now #{ e.currentTarget.value }")

https://jsfiddle.net/sr3tkaw7/3/

与jQuery:

$("#notes").change (e) ->
  alert("Note content changed. Is now #{ $(e.currentTarget).val() }")

https://jsfiddle.net/sr3tkaw7/4/