我正在使用nicedit(http://nicedit.com/index.php)。
我一直试图创建一个默认的html文本区域,当你点击它时,它会变成一个nicedit文本域。我希望它在失去焦点时恢复为纯html文本区域。当我只使用一个文本区域时,我已经成功地做到了这一点,然而,当我使用两个文本区域时,奇怪的事情就会发生(在firefox中)。我使用以下脚本:
<script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script> <script type="text/javascript">
function fieldname_1()
{
area = new nicEditor({fullPanel : true}).panelInstance('fieldname');
area.addEvent('blur', function()
{
area.removeInstance('fieldname');
area = null;
document.getElementById("fieldname").onclick=function(){fieldname_2()}
});
}
function fieldname_2()
{
area = new nicEditor({fullPanel : true}).panelInstance('fieldname');
area.addEvent('blur', function()
{
area.removeInstance('fieldname');
area = null;
document.getElementById("fieldname").onclick=function(){fieldname_1()}
});
}
function fieldname2_1()
{
area = new nicEditor({fullPanel : true}).panelInstance('fieldname2');
area.addEvent('blur', function()
{
area.removeInstance('fieldname2');
area = null;
document.getElementById("fieldname2").onclick=function(){fieldname2_2()}
});
}
function fieldname2_2()
{
area = new nicEditor({fullPanel : true}).panelInstance('fieldname2');
area.addEvent('blur', function()
{
area.removeInstance('fieldname2');
area = null;
document.getElementById("fieldname2").onclick=function(){fieldname2_1()}
});
}
</script>
<TEXTAREA id="fieldname" cols="35" onclick="fieldname_1();" ></TEXTAREA>
<br><br><br>
<TEXTAREA id="fieldname2" cols="35" onclick="fieldname2_1();" >Test text</TEXTAREA>
您单击并取消聚焦的第一个文本区域工作正常,但是,尝试取消聚焦时,您单击的第二个文本区域不会消失。我做错什么了?
最佳答案
你不能用一个以上的短信区,1000个怎么样?
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title></title>
<script src = "http://js.nicedit.com/nicEdit-latest.js"></script>
<script>
window.onload = function () {
var body = document.body;
var limit = 1000;
for (var i = 0; i < limit; i ++) {
var textarea = document.createElement ("textarea");
textarea.style.height = "100px";
textarea.style.width = "100%";
body.appendChild (textarea);
}
// The magic
body.addEventListener ("click", function (event) {
var target = event.target;
if (target.nodeName === "TEXTAREA") {
var area = new nicEditor ({fullPanel : true}).panelInstance (target);
area.addEvent ("blur", function () {
this.removeInstance (target);
});
}
}, false);
}
</script>
<style>
textarea {
height: 100px;
margin-bottom: 20px;
width: 1000px;
}
</style>
</head>
<body>
<!-- Create any textarea you want -->
</body>
</html>
关于javascript - Javascript:在HTML textarea和nicedit之间切换的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4855071/