我想在html编辑器(而不是导航栏)中添加可点击的按钮/图像/ div。但是,当我使用onBeforeSetContent.add函数过滤内容并添加带有onclick标记的元素时,该标记将被剥离。
由于我使用的是Wordpress,因此所有操作均通过tinymce插件完成。
//replace shortcode before editor content set
ed.onBeforeSetContent.add(function(ed, o) {
o.content = t.filter_content(o.content);
});
...
filter_content : function(co) {
return co.replace(/\[icitspot([^\]]*)\]/g, function(a,b){
return '<img src="#" onclick="alert(\'abc\')" class="wpSpot mceItem" title="clickme" />';
});
},
通常应检测到单击事件,而不是使用onclick属性:
ed.onClick.add(function(ed, e) {
console.log(e.target);
});
现在,您可以检测到单击的元素并确定是否是您的按钮/ div。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句