主頁(yè) > 知識(shí)庫(kù) > tinyMCE插件開(kāi)發(fā)之插入html,php,sql,js代碼 并代碼高亮顯示

tinyMCE插件開(kāi)發(fā)之插入html,php,sql,js代碼 并代碼高亮顯示

熱門(mén)標(biāo)簽:溫嶺代理外呼系統(tǒng) 寧夏保險(xiǎn)智能外呼系統(tǒng)哪家好 激戰(zhàn)黃昏地圖標(biāo)注說(shuō)明 防城港市ai電銷(xiāo)機(jī)器人 臨滄移動(dòng)外呼系統(tǒng)哪家有 不同的地圖標(biāo)注 隨州銷(xiāo)售外呼系統(tǒng)平臺(tái) 交行外呼系統(tǒng)有哪些 怎么更改地圖標(biāo)注電話
下面就是我開(kāi)發(fā)的過(guò)程。
首先,我的 tinyMCE版本是 Version: 3.2.7 (2009-09-22) 。
下載地址 https://www.jb51.net/codes/17198.html
tinyMCE插入代碼,需要調(diào)用 tinyMCE的 tinyMCE.execCommand('mceInsertContent',false,value); 方法。其中參數(shù)無(wú)需改變,value 就是你要插入的內(nèi)容,
比如我寫(xiě)了一個(gè)函數(shù),
復(fù)制代碼 代碼如下:

function InsertHTML(value)
{
tinyMCE.execCommand('mceInsertContent',false,value);
}

后面,針對(duì)該例子,提供下載。在例子中。一共涉及到三個(gè)文件。
tinyMCE.html insertcode.php save.php 這三個(gè)文件。
tinyMCE.html 是tinyMCE文本框頁(yè)面。
主要代碼如下:
復(fù)制代碼 代碼如下:

script type="text/javascript" src="https://www.jb51.net/tinymce/tiny_mce.js">/script>
script type="text/javascript">
tinyMCE.init({
// General options
convert_urls : false,
mode : "exact",
elements : "Article_Content",
//mode : "textareas",
theme : "advanced",
plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Example content CSS (should be your site CSS)
content_css : "css/content.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",
// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
/script>
script type="text/javascript">
function InsertHTML(value)
{
tinyMCE.execCommand('mceInsertContent',false,value);
}
/script>

其中js代碼是初始化 tinyMCE。下載的例子中,并未包含 tinyMCE,你需要自己下載。然后 更改js代碼的 src 即可。
復(fù)制代碼 代碼如下:

input name="button" type="button" onclick="window.open('insertcode.php','插入代碼','height=500, width=600, top=300, left=300, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')" value="點(diǎn)擊這里插入代碼" />

上面這段代碼,是用來(lái)打開(kāi)insertcode.php文件的。
接下來(lái),我們來(lái)看下 insertcode。php 這個(gè)文件的代碼。
首先是 js 代碼
復(fù)制代碼 代碼如下:

script language="javascript" src="http://www.gosoa.com.cn/js/jquery.js">/script>
script language="javascript">
function insertcode()
{
var value = $('#postcontent').html();
var codetype = $('#codetype').val();
// window.opener.InsertHTML('textarea rows="3" cols="50" name="code" class="'+codetype+'">'+value+'/textarea>');
window.opener.InsertHTML('pre name="code" class="'+codetype+'">'+value+'/pre>');
window.close();
}
/script>

其次是 PHP 和 html 代碼
復(fù)制代碼 代碼如下:

?php
error_reporting(0);
$content = $_POST['content'];
if(!empty($content))
{
    $codetype = $_POST['codetype'];
    echo 'div id="postcontent">';
    $content = htmlspecialchars($content);
    echo $content;
    echo '/div>
    input type="hidden" name="codetype" id="codetype" value="'.$codetype.'" />
    input type="button" name="Submit" value="提交" onclick="insertcode()" style="border:1px solid #000; line-height:18px; width:60px;"/>';
}else
{
?>
div style="margin:0 auto">
form id="form1" name="form1" method="post" action="insertcode.php">
label>選擇要插入的代碼類(lèi)型
select name="codetype" id="codetype">
    option value='php'>php/option>
    option value='js'>js/option>
    option value='html'>html/option>
    option value='c'>c/option>
    option value='asp'>asp/option>
    option value='xml'>xml/option>
    option value='java'>java/option>
    option value='java'>java/option>
    option value='CSharp'>C#/option>
    option value='sql'>SQL/option>
/select>
/label>
label>
textarea name="content" id="content" cols="30" rows="20" style="width:600px; height:200px; border:1px dashed #333">/textarea>
/label>
p>
label style="padding-left:50px;">
input type="Submit" name="Submit" value="提交" style="border:1px solid #000; line-height:18px; width:60px;"/>
/label>
/p>
p>nbsp;/p>
/form>
/div>
?php
}    
?>

在insertcode.php中,insertcode() 函數(shù)用來(lái)調(diào)用 tinyMCE.html頁(yè)面的 insertHTMl()函數(shù),并將代碼插入到 tinyMCE.html 頁(yè)面中。
代碼中,我們?yōu)槭裁匆?'+value+' 呢?
因?yàn)槲覀冊(cè)陲@示頁(yè)面,將會(huì)采用 SyntaxHighlighter 插件來(lái)高亮顯示代碼。
還有一點(diǎn)要說(shuō)明,在這里,$content = htmlspecialchars($content); 我們對(duì)于代碼本身,進(jìn)行了 htmlspecialchars 轉(zhuǎn)義操作。這樣,插入數(shù)據(jù)庫(kù)的代碼則會(huì)是安全的。
OK,我們?cè)賮?lái)看 save.php,該頁(yè)面用來(lái)顯示 提交的內(nèi)容。
主要代碼如下:
復(fù)制代碼 代碼如下:

?
$Article_Content = $_POST['Article_Content'];
function transcode($str)
{
if(empty($str))
{
return false;
}
$str = str_replace('"','"',$str);
$str = str_replace('','',$str);
$str = str_ireplace('lt;BRgt;',"n",$str);
$str = str_ireplace('pre','pre name="code" ',$str);
return $str;
}
echo transcode($Article_Content);
?>
script class="javascript" src="/tinymce/lightcode/Scripts/shCore.js">/script>
script class="javascript" src="/tinymce/lightcode/Scripts/shBrushCSharp.js">/script>
script class="javascript" src="/tinymce/lightcode/Scripts/shBrushPhp.js">/script>
script class="javascript" src="/tinymce/lightcode/Scripts/shBrushJScript.js">/script>
script class="javascript" src="/tinymce/lightcode/Scripts/shBrushJava.js">/script>
script class="javascript" src="/tinymce/lightcode/Scripts/shBrushVb.js">/script>
script class="javascript" src="/tinymce/lightcode/Scripts/shBrushSql.js">/script>
script class="javascript" src="/tinymce/lightcode/Scripts/shBrushXml.js">/script>
script class="javascript" src="/tinymce/lightcode/Scripts/shBrushDelphi.js">/script>
script class="javascript" src="/tinymce/lightcode/Scripts/shBrushPython.js">/script>
script class="javascript" src="/tinymce/lightcode/Scripts/shBrushRuby.js">/script>
script class="javascript" src="/tinymce/lightcode/Scripts/shBrushCss.js">/script>
script class="javascript" src="/tinymce/lightcode/Scripts/shBrushCpp.js">/script>
script class="javascript">
dp.SyntaxHighlighter.HighlightAll('code');
/script>

OK,完了。
^_^ ~~~
tinyMCE 插件開(kāi)發(fā)之插代碼高亮 v1.0 (支持html,php,sql,js)
您可能感興趣的文章:
  • Sql Server 如何去掉內(nèi)容里面的Html標(biāo)簽
  • js+html5操作sqlite數(shù)據(jù)庫(kù)的方法
  • 分享php代碼將360瀏覽器導(dǎo)出的favdb的sqlite數(shù)據(jù)庫(kù)文件轉(zhuǎn)換為html
  • PHP HTML JavaScript MySQL代碼如何互相傳值的方法分享
  • Java SQL注入案例教程及html基礎(chǔ)入門(mén)

標(biāo)簽:河源 忻州 沈陽(yáng) 紅河 哈密 無(wú)錫 青海 阜陽(yáng)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《tinyMCE插件開(kāi)發(fā)之插入html,php,sql,js代碼 并代碼高亮顯示》,本文關(guān)鍵詞  tinyMCE,插件,開(kāi),發(fā)之,插入,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《tinyMCE插件開(kāi)發(fā)之插入html,php,sql,js代碼 并代碼高亮顯示》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于tinyMCE插件開(kāi)發(fā)之插入html,php,sql,js代碼 并代碼高亮顯示的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章