我将会使用xheditor作为新的在线编辑器,我希望它可以能通过一个php函数就能调用如
function editor($content,$name)
{
$editor=<<<EOT
<textarea id="$name" name="$name" rows="10" cols="60">$content</textarea>
EOT;
return $editor;
}
这样做的好处有:
1,不用每次调用xheditor编辑器,都在前面写一大
2,调用方便,模板上就放返回的html代码的变量就可以了。
我使用的方法是用jquery里的get()方法异步xheditor的代码,然后再用eval把代码运行了。
如下:
function editor($content,$name)
{
$editor=<<<EOT
$(document).ready(
function(){
if(!$.isFunction($.xheditor))
{
$.get(
'../xheditor.js',
function(data){
eval(data);
}
);
}
$('#{$name}').xheditor(true);
}
);
<textarea id="$name" name="$name" rows="10" cols="60">$content</textarea>
EOT;
return $editor;
}
以上就是【xhEditor的异步载入实现代码】的全部内容了,欢迎留言评论进行交流!