ThinkPHP讲解(十二)——文本编辑器和ajax传址
生活随笔
收集整理的這篇文章主要介紹了
ThinkPHP讲解(十二)——文本编辑器和ajax传址
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、文本編輯器
1.首先,在網上下載ueditor文件
2.在要添加文本編輯器的頁面中引用ueditor文件中的js文件
<script type="text/javascript" charset="utf-8" src="../ueditor/utf8-php/ueditor.config.js"></script> <script type="text/javascript" charset="utf-8" src="../ueditor/utf8-php/ueditor.all.min.js"> </script><!--建議手動加在語言,避免在ie下有時因為加載語言失敗導致編輯器加載失敗--><!--這里加載的語言文件會覆蓋你在配置項目里添加的語言類型,比如你在配置項目里配置的是英文,這里加載的中文,那最后就是中文--> <script type="text/javascript" charset="utf-8" src="../ueditor/utf8-php/lang/zh-cn/zh-cn.js"></script>
3.在要添加文本編輯器的頁面中添加前端的代碼
<div><script id="editor" type="text/plain" style="width:1024px;height:500px;"></script> </div>添加的按鈕:
<div> <button οnclick="getContent()">獲得內容</button> <button οnclick="setContent()">寫入內容</button> </div>
4.按鈕實現的js代碼
<script type="text/javascript"> //初始化 var ue = UE.getEditor('editor'); //獲得內容 function getContent() {var a=UE.getEditor('editor').getContent(); document.getElementById("xianshi").innerHTML=a;} //寫入內容 function setContent(isAppendTo) {var str="趙詩濤";UE.getEditor('editor').setContent(str, isAppendTo);}
5.
?
?
?
二、ajax傳遞圖片地址
1、前端圖片代碼
<img src="img/aa.jpg" id="img"/>
2.圖片ajax自動儲存到數據庫
<script type="text/javascript"> $(document).ready(function(e) {var url=$("#img").attr("src");var lujing = encodeURIComponent(url); //路徑編碼$.ajax({url:"chuli.php",data:{url:lujing},type:"POST",dataType:"TEXT",success: function(data){}}); }); </script>
3.后端處理代碼
<?php $url=$_POST["url"];$lujing=urldecode($url);//路徑解碼include("../DBDA.class.php"); $db=new DBDA(); $sql="insert into nation values('n018','{$lujing}')"; //echo $sql; $db->Query($sql,1);
轉載于:https://www.cnblogs.com/zst062102/p/5657202.html
總結
以上是生活随笔為你收集整理的ThinkPHP讲解(十二)——文本编辑器和ajax传址的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 前端开发_python和前
- 下一篇: mysql dbutil_DBUtil连