我使用nicEdit作为本地站点的记事本编辑器。我使用复选框来调用nicEdit函数(注释),但是该面板根本不显示。甚至警报也不会显示。
还有其他三个功能可以使用cookie保存注释:
//annotation
function annotation(player1) {
bkLib.onDomLoaded(function(){
new nicEditor({
fullPanel : true,
onSave : function(content, id, instance) {
var player_name = document.getElementById('player1').value;
alert(player_name);
checkCookie(player_name);
setCookie(content,player_name);
}
}).panelInstance('myArea');
});
}
function setCookie(content,player) {
var d = new Date();
d.setTime(d.getTime() + (365*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = player + "=" + content + "; " + expires;
}
//check if the coockie with current player name exists
function checkCookie(player_name) {
var pnote = getCookie( player_name );
//alert(pnote);
if ( pnote!="" ) {
$(".nicEdit-main").append(pnote);
} else {
if ( player_name != "" && player_name != null ) {
$(".nicEdit-main").append("");
alert("nothing");
}
}
}
//Gets the cookie content
function getCookie(player_name) {
var name = player_name + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return "";
}
<textarea style="height: 300px;" cols="52" id="myArea" name="myArea" style="width:450px; " ></textarea>
<input type="checkbox" onclick="annotation(player1)" id="player1" value="player1">player1 <br>
最佳答案
好吧,打电话
bkLib.onDomLoaded(function(){}
在您的注释功能中是错误的。
这是使用jquery处理click事件的一种方法。
$('#player1').click(function () {
alert("player");
new nicEditor({
fullPanel : true,
onSave : function(content, id, instance) {
var player_name = document.getElementById('player1').value;
alert(player_name);
checkCookie(player_name);
setCookie(content,player_name);
}
}).panelInstance('myArea');
});
jsfiddle https://jsfiddle.net/cqcu0hbp/的完整示例