我有一个CKeditor,可以加载包括html文本在内的文本。 HTML文本具有分配给某些跨度文本区域的CSS类。当用户在CKEditor文本框中的具有特定类的跨度包围的文本上进行鼠标悬停或鼠标单击时,我想触发鼠标悬停事件或click事件。
这是我以编程方式加载到CKEditor中的文本
var editorHtml = '<span class="noedit">no edit text</span> edit this';
我正在尝试通过此代码捕获事件。
$(document).ready(function () {
$('.noedit').mouseover(function () {
alert('hello');
});
});
它似乎不起作用。我究竟做错了什么?这有可能吗?
最佳答案
尝试在此处使用event delegation,因为您的跨度可能是CKEditor
在此处动态添加的:
$(document).ready(function () {
$(document).on('mouseover','.noedit', function() {
alert('hello');
});
});