如题,很郁闷,弄了一个星期了,问题还是得不到解决!!
我在当前页面中 譬如 A.php点击一个链接onclick事件触发ajax在弹出窗口中加载页面B.html. editor编辑器无法显示在加载的B.html的文本框上,搜遍百度,研究N遍kindeditor文档,即使按照网上介绍的方法在ajax回调函数中引用kindeditor JS文件同样不能显示,十分的困惑!!!!! 代码如下:
//A.PHP 代码
.....头部
<script charset="utf-8" src="editor/kindeditor.js"></script>
<script charset="utf-8" src="editor/lang/zh_CN.js"></script>
<script>
var editor;
KindEditor.ready(function(K) {
editor = K.create('#editor_id');
html = editor.html();
editor.sync();
html = document.getElementById('editor_id').value;
editor.html();
});
.....
...body部分
..........
<span id="publication"><a class="publication" href="#">发布新闻文章</a></span> //点击触发AJAX链接
.......
<div id="alert2"> 显示AJAX返回的B.html </div> 层
//B.html 加载页面代码
<h4><span style="margin-left:10px;">发布新闻</span><span id="close2">关闭</span></h4>
<form name="news" method="POST">
<p><input id="title" type="text" name="title" value="请填写文章标题" onFocus="if (value =='请填写文章标题'){value =''}" onBlur="if (value ==''){value='请填写文章标题'}" /><span id="news_title">*</span></p>
<p class="select">
<select name="news_type" id="news_type">
<option value="default">请选择新闻类别</option>
<option value="公司新闻">公司新闻</option>
<option value="行业新闻">行业新闻</option>
</select>
<span id="news_class">*</span>
</p>
<p>* 温馨提示:文章内容不能超过2000字!<span id="content_reminding" margin-left:10px;></span></p>
<p><textarea id="editor_id" type="text" name="content"></textarea></p>
<p class="submit"><input type="button" name="submit" value="保存" class="submit" onclick="Submit();" /><input type="reset" value="重置" class="submit" /><span id="loading" style="margin-left:20px;"></span></p>
</form>
ajax 代码
//发布新闻变量设置
var myAlert2 = document.getElementById("alert2");
var reg2 = document.getElementById("publication").getElementsByTagName("a")[0];
var reg3 = document.getElementById("edit").getElementsByTagName("a")[0];
//弹出窗口
function click()
{
myAlert2.style.display = "block";
myAlert2.style.position = "absolute";
myAlert2.style.zIndex = "1000";
myAlert2.style.top = "50%";
myAlert2.style.left = "50%";
myAlert2.style.marginTop = "-300px";
myAlert2.style.marginLeft = "-300px";
myAlert2.style.border= "1px solid #333";
myAlert2.style.width = "600px";
myAlert2.style.paddingBottom = "5px";
myAlert2.style.khtmlBorderRadius = "5px";
myAlert2.style.mozBorderRadius = "5px";
myAlert2.style.webkitBorderRadius = "5px";
myAlert2.style.borderRadius = "5px";
myAlert2.style.webkitBoxShadow = "0 0 5px #666";
myAlert2.style.mozBoxShadow = "0 0 5px #666";
myAlert2.style.boxShadow = "0px 0 5px #666";
myAlert2.style.background = "#fff";
mybg2 = document.createElement("div");
mybg2.setAttribute("id","mybg2");
mybg2.style.background = "#000";
mybg2.style.width = "100%";
mybg2.style.height = "100%";
mybg2.style.position = "absolute";
mybg2.style.top = "0";
mybg2.style.left = "0";
mybg2.style.zIndex = "500";
mybg2.style.opacity = "0.3";
mybg2.style.filter = "Alpha(opacity=30)";
document.body.appendChild(mybg2);
document.body.style.overflowX = "hidden";
}
reg2.onclick= function public(){
click();
Request();
}
reg3.onclick= function edit(){
click();
Request2();
};
function ajax(){
var xmlhttp = false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function Request(){
var xmlhttp = ajax();
var url="newspublication.php";
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
document.getElementById('alert2').innerHTML = process_request;//显示状态
xmlhttp.onreadystatechange=function status(){
if (4==xmlhttp.readyState){
if (200==xmlhttp.status)
{
var responseText = xmlhttp.responseText;
if (responseText)
{
function scrpt(url)
{
var js = document.createElement("script"); //加载kindeditor js文件
js.setAttribute("type","text/javascript");
js.setAttribute("src",url);
document.body.appendChild(js);
}
document.getElementById('alert2').innerHTML = responseText; //加载页面到alert2指定层
url1="editor/kindeditor.js";
url2="editor/lang/zh_CN.js";
scrpt(url1);
scrpt(url2);
var editor;
KindEditor.ready(function(K)
{
editor = K.create('#editor_id');
html = editor.html();
editor.sync();
html = document.getElementById('editor_id').value;
editor.html();
});
var mClose2 = document.getElementById("close2"); //弹出框关闭按钮JS函数
mClose2.onclick = function close()
{
myAlert2.style.display = "none";
mybg2.style.display = "none";
}
}
else
{
alert("发生错误!");
window.location.href="news_center.php";
}
}
}
}
}
function Request2()
{
var xmlhttp = ajax();
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
document.getElementById('alert2').innerHTML = process_request;//显示状态
xmlhttp.onreadystatechange=function status(){
if (4==xmlhttp.readyState){
if (200==xmlhttp.status)
{
var responseText = xmlhttp.responseText;
if (responseText)
{
document.getElementById('alert2').innerHTML = responseText; //加载页面到alert2指定层
var mClose2 = document.getElementById("close2"); //弹出框关闭按钮JS函数
mClose2.onclick = function close()
{
myAlert2.style.display = "none";
mybg2.style.display = "none";
}
}
else
{
alert("发生错误!");
window.location.href="news_center.php";
}
}
}
}
}
var process_request = "<center><img src='img/loading.gif' border='0' align='absmiddle'>页面加载中...</center>";