<script type="text/javascript">
$( "#x_img" ).load( "../x_img.php?id=123" );
$("#x_img").delegate("img", "click",function() {
CKEDITOR.instances.editor1.insertHtml('<img src="'+$(this).attr('alt')+'" />');
});
</script>
我有一个加载图像(x_img)供用户使用的函数。 x_img jq.load 在此页面中。
使用此代码,我单击要插入的图像,效果很好。但是,我无法获取图像 src
值(value)!
CKEditor 显示:<img src="undefined" />
问题是图像在另一个页面上吗?
最佳答案
如果您的编辑器正在显示
<img src="undefined" />
然后
$(this).attr('alt')
将返回undefined
因为img
节点没有alt='something'
属性。这个undefined
然后被连接到您的 img
的src
属性。
尝试将图像标记更改为如下所示:
<img alt="/images/funtimesatthebeach.jpg" />
然后,您的代码应该加载 /images/funtimesatthebeach.jpg
处的图像。 .
关于javascript - ckeditor insertHtml() 形式 jquery.load,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27323958/