ckeditor insertHtml()形式jquery.load

时间:2014-12-05 20:14:09

标签: javascript jquery ckeditor

<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的价值!

CKEditor显示:<img src="undefined" />

图像是否在另一页上的问题?

1 个答案:

答案 0 :(得分:1)

如果你的编辑正在展示

<img src="undefined" />

然后

$(this).attr('alt')

将返回undefined,因为img节点没有alt='something'属性。然后,此undefined会合并到您的img src属性中。

尝试将图片代码更改为以下内容:

<img alt="/images/funtimesatthebeach.jpg" />

然后,您的代码应该在/images/funtimesatthebeach.jpg加载图片。