ueditor文字框初始化如何顯示預設內容,以及文字框獲取焦點後清空預設內容
阿新 • • 發佈:2018-12-26
<div> <form id="myForm" method="post" action="<?=Url::toRoute(['save'])?>"> <!-- 正文 --> <!-- 載入編輯器的容器 --> <script id="container" name="content" type="text/plain" style="height:150px"></script> <input type="hidden" name="image" id="image" value="" > </form> </div> <!-- 配置檔案 --> <script type="text/javascript" src="ueditor.config.js"></script> <!-- 編輯器原始碼檔案 --> <script type="text/javascript" src="ueditor.all.js"></script> <!-- 例項化編輯器 --> <script type="text/javascript"> var ue = UE.getEditor('container', { toolbars: [[ 'fullscreen', 'source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'fontborder', 'forecolor', 'backcolor', 'fontsize', '|', 'simpleupload', 'link' ]], serverUrl:'<?=\yii\helpers\Url::toRoute('upload')?>', }); //預設顯示內容必須在例項化編輯器之後才能顯示 ue.ready(function() { //預設顯示內容 ue.setContent('<p style="color:silver">文明發言,如有違反,後果將由您個人自行承擔。</p>'); //文字框獲取焦點時清空預設顯示的內容 ue.addListener("focus", function(){ ue.setContent(''); }); //文字框是去焦點時,若內容為空則顯示預設顯示的內容 ue.addListener("blur", function(){ if(!ue.getContent()){ ue.setContent('<p style="color:silver">文明發言,如有違反,後果將由您個人自行承擔。</p>'); } }); }); </script>