亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

動態增加的div沒有文本編輯器

動態增加的div沒有文本編輯器

風雪與默默 2016-11-24 00:03:31
在一個頁面的多個div里加上contenteditable="true",就可以實現inline效果。 但是,我現在在頁面中實現了點擊按鈕,動態增加一個div的效果,新增加的div也有contenteditable="true",但是獲得焦點是文本編輯器卻沒有出現。 希望遇見過這個問題的人給個建議。謝謝!
查看完整描述

2 回答

已采納
?
qq_青棗工作室_0

TA貢獻446條經驗 獲得超754個贊

原來你說的是CKEditor??!可以的:

<!doctype?html>
<meta?charset=utf-8>
<style>div[contenteditable=true]{border:?1px?solid?#000;}</style>
<script?src="./ckeditor/ckeditor.js"></script>
<div?id="editor1"?contenteditable="true">測試文本</div>
<button?id="btn">按鈕</button>
<script>
????CKEDITOR.disableAutoInline?=?true;
????CKEDITOR.inline(?'editor1'?);

????document.getElementById('btn').onclick?=?function()?{
????	var?div?=?document.createElement('div');
????	div.setAttribute('contenteditable',?"true");
????	document.body.appendChild(div);
????	CKEDITOR.inline(div);
????}
</script>


查看完整回答
2 反對 回復 2016-11-24
  • 風雪與默默
    風雪與默默
    我昨晚剛剛試出來只要加一行CKEDITOR.inline(&#039;id &#039;)就行,也非常感謝您!
?
qq_青棗工作室_0

TA貢獻446條經驗 獲得超754個贊

我測試過,IE7不行,IE8+和Chrome都行的。

<!doctype?html>
<meta?charset=utf-8>
<style>
????div?{border:?1px?solid?#777;height:?20px;}
</style>
<script>
function?add()?{
????var?div?=?document.createElement('div');
????div.setAttribute('contenteditable',?true);
????document.body.appendChild(div);
}	
</script>
<div?contenteditable="true"></div>
<input?type="button"?value="按鈕"?onclick="add()">


查看完整回答
反對 回復 2016-11-24
  • 2 回答
  • 0 關注
  • 1510 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號