问题:
在KindEditor中插入input输入框,更改其height,width,value后,再次获取html代码,height和width已被更新,但是value还是初始值。而且,onclick()方法的代码没有传送到服务器当中。
问题代码"hello.js":
KindEditor.plugin_new('hello', function(K) {
var editor = this, name = 'hello';
// 点击图标时执行
editor.clickToolbar(name, function() {
var plugin_id = name + "#kedit#" + new Date().getTime();
var html = '<input id=' + plugin_id +' type=text style=width:100px;height:20px value=100>';
editor.insertHtml(html);
});
}, function(K, e){
var html= ['<div style="padding:20px;">',
'控件id:' + e.target.id + '<br>',
'<label>宽: <input type=text id=width /></label><br>',
'<label>高: <input type=text id=height /></label><br>',
'<label>值: <input type=text id=value /></label><br>',
'<label>onclick: <textarea id=t style=width:300px;height:200px></textarea></label><br>',
'</div>'].join('');
var dialog = K.dialog({
width : 500,
height: 400,
title : '编辑窗口',
body : html,
closeBtn : {
name : '关闭',
click : function(e) {
dialog.remove();
}
},
yesBtn : {
name : '确定',
click : function() {
var e_target = window.frames[0].document.getElementById(e.target.id);
var input_width = document.getElementById("width").value;
var input_height = document.getElementById("height").value;
var input_value = document.getElementById("value").value;
var input_t = document.getElementById("t").value;
if(input_width != "" && input_height != "" && input_value != ""){
<span style="color:#33CCFF;"><span style="color:#993399;">e_target.style.width = input_width;
e_target.style.height = input_height;
e_target.style.value = input_value;
var fn = new Function(input_t);
e_target.onclick = fn; </span> </span>
dialog.remove();
}
else{
alert("属性值不能为空");
}
}
},
noBtn : {
name : '取消',
click : function() {
dialog.remove();
}
}
});
});
修改代码:
e_target.style.width = input_width;
e_target.style.height = input_height;
<span style="color:#3366FF;">e_target.setAttribute("value", input_value);
e_target.setAttribute("onclick", input_t);</span>
修改后效果:
意外收获:confirm,alert,prompt的区别:
http://developer.51cto.com/art/200906/129845.htm
心得:
尝试使用editor.sync()同步数据,但是没有成功。希望日后找到问题原因。