欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

xhEditor的異步載入實(shí)現(xiàn)代碼

 更新時(shí)間:2009年11月19日 12:07:51   作者:  
xhEditor的異步載入實(shí)現(xiàn)代碼,需要的朋友可以參考下。

我將會(huì)使用xheditor作為新的在線編輯器,我希望它可以能通過(guò)一個(gè)php函數(shù)就能調(diào)用如

復(fù)制代碼 代碼如下:

function editor($content,$name)
{
$editor=<<<EOT
<textarea id="$name" name="$name" rows="10" cols="60">$content</textarea>
EOT;
  return $editor;
}

這樣做的好處有:
1,不用每次調(diào)用xheditor編輯器,都在前面寫一大
2,調(diào)用方便,模板上就放返回的html代碼的變量就可以了。

我使用的方法是用jquery里的get()方法異步xheditor的代碼,然后再用eval把代碼運(yùn)行了。
如下:

復(fù)制代碼 代碼如下:

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;
}

以上代碼正確情況下,你是運(yùn)行不了。
因?yàn)閤heditor的0.9.8版在異步載入時(shí)會(huì)出現(xiàn)問(wèn)題。導(dǎo)致xheditor不能正常顯示。
原因:
由于jsURL是通過(guò)獲取頁(yè)面的來(lái)得到的。但我是采用異步加載的,所以我需要指定jsURL的地址。

補(bǔ)?。?BR>打開xheditor.js找到以下代碼

復(fù)制代碼 代碼如下:

var defaults={skin:"default",tools:"full",internalScript:false,inlineScript:false,internalStyle:false,inlineStyle:true,showBlocktag:false,forcePtag:true,keepValue:true,upLinkExt:"zip,rar,txt",upImgExt:"jpg,jpeg,gif,png",upFlashExt:"swf",upMediaExt:"avi",modalWidth:350,modalHeight:220,modalTitle:true};


改為
復(fù)制代碼 代碼如下:

var defaults={skin:"default",tools:"full",internalScript:false,inlineScript:false,internalStyle:false,inlineStyle:true,showBlocktag:false,forcePtag:true,keepValue:true,upLinkExt:"zip,rar,txt",upImgExt:"jpg,jpeg,gif,png",upFlashExt:"swf",upMediaExt:"avi",modalWidth:350,modalHeight:220,modalTitle:true,editorURL:null};

其實(shí)就是增加了editorURL的默認(rèn)值
然后再找到

復(fù)制代碼 代碼如下:

this.settings=$.extend({},defaults,options);

在其后面添加
復(fù)制代碼 代碼如下:

jsURL= this.settings.editorURL||jsURL;

用于設(shè)置jsURL是使用默認(rèn)值還是用戶自定義的目錄

以后在調(diào)用xheditor時(shí)就多了一個(gè)參數(shù)

復(fù)制代碼 代碼如下:

editorURL
編輯器所在的url路徑,該路徑必須帶有“/”,默認(rèn)值為null

在瀏覽器里打開根目錄的load_xheditor.html
文件打包

相關(guān)文章

最新評(píng)論