前段时间,利用ajax写了一个论坛帖子的列表页面。发表帖子的内容是用xheditor编辑器做的。代码如下:
$(document).ready(function(){
//初始化编辑器
$(pageInit);
function pageInit()
{
var editor=$('#txtcontent').xheditor({tools:'simple',skin:'default'});
}
//点击发表帖子按钮时,获取编辑器文本框内容
$("#lnkbtnReply").click(function(){
if(islogin==0)
{
alert("您还没有登录呢");
window.location.href=URL;
return false;
}
else if(islogin==1)
{
var titles=$("#txtTopic").val();
if(titles=="")
{
alert("请输入主题");
return false;
}
}
});
//菜单导航样式
$("#menu ul li").hover(function(){
$(this).find("a:first").addClass("ahover");
},function(){
$(this).find("a:first").removeClass("ahover");
});
//以下操作主要用于显示帖子以及相关的操作
GetTopicList(pageindex,topictypeid,ordertype,ordertype1);//帖子列表
GetTopicListCount(topictypeid);//帖子总页数
$("#current").text(pageindex);//当前页
//最热帖子排序
$("#hottz").click(function(){
pageindex=1;
ordertype=1;//改为热门帖子
if(ordertype1==1)
{
ordertype1=0;//按降序
GetTopicList(pageindex,topictypeid,ordertype,ordertype1);//帖子列表
}
else
{
ordertype1=1;
GetTopicList(pageindex,topictypeid,ordertype,ordertype1);//帖子列表
}
});
//最新帖子排序
$("#newtz").click(function(){
pageindex=1;
ordertype=0;
if(ordertype1==1)
{
ordertype1=0;
}
else
{
ordertype1=1;
}
GetTopicList(pageindex,topictypeid,ordertype,ordertype1);//帖子列表
});
//首页
$("#first").click(function(){
pageindex=1;
$("#current").text(pageindex);//当前页
$("#zxy").val(pageindex);//转向页
GetTopicList(pageindex,topictypeid,ordertype,ordertype1);//帖子列表
});
//上一页
$("#pre").click(function(){
var zys=$("#total").text();
if(pageindex>1&&pageindex<=zys)
{
pageindex--;
$("#current").text(pageindex);//当前页
$("#zxy").val(pageindex);//转向页
GetTopicList(pageindex,topictypeid,ordertype,ordertype1);//帖子列表
}
});
//下一页
$("#next").click(function(){
var zys=$("#total").text();
if(pageindex<zys&&pageindex>=1)
{
pageindex++;
$("#current").text(pageindex);//当前页
$("#zxy").val(pageindex);//转向页
GetTopicList(pageindex,topictypeid,ordertype,ordertype1);//帖子列表
}
});
//末页
$("#last").click(function(){
var zys=$("#total").text();
pageindex=zys;
$("#current").text(pageindex);//当前页
$("#zxy").val(pageindex);//转向页
GetTopicList(pageindex,topictypeid,ordertype,ordertype1);//帖子列表
});
//转向哪一页
$("#btnGo").click(function(){
var zys=$("#total").text();//总页数
var zxys=$("#zxy").val();//转向哪一页
if(zxys<=zys&&zxys>=pageindex)
{
pageindex=zxys;
$("#current").text(pageindex);//当前页
$("#zxy").val(pageindex);//转向页
GetTopicList(pageindex,topictypeid,ordertype,ordertype1);//帖子列表
}
else if(zxys<=1)//输入的数小于1,转向第一页
{
pageindex=1;
$("#current").text(pageindex);//当前页
$("#zxy").val(pageindex);//转向页
GetTopicList(pageindex,topictypeid,ordertype,ordertype1);//帖子列表
}
else if(zxys>zys)//输入的数大于总页数,转向末页
{
pageindex=zys;
$("#current").text(pageindex);//当前页
$("#zxy").val(pageindex);//转向页
GetTopicList(pageindex,topictypeid,ordertype,ordertype1);//帖子列表
}
});
//以下是搜索文本框操作
$('#txtsearch').bind('keypress',function(event){
if(event.keyCode == "13")
{
var keywords=$("#txtsearch").val();//输入的搜索内容
keywords=keywords.replace(/^\s+|\s+$/g,"");
var urls="";
if(keywords==""||keywords=="请输入搜索关键字")
{
alert("请输入搜索关键字");
}
else
{
urls="bbsSearch.aspx?keywords="+escape(keywords);
window.open(urls,"_blank");
}
}
});
//点击按钮搜索
$("#searchs").click(function(){
var keywords=$("#txtsearch").val();//输入的搜索内容
keywords=keywords.replace(/^\s+|\s+$/g,"");
var urls="";
if(keywords==""||keywords=="请输入搜索关键字")
{
alert("请输入搜索关键字");
}
else
{
urls="bbsSearch.aspx?keywords="+escape(keywords);
window.open(urls,"_blank");
}
});
})
出现了无法获取编辑器中的内容,在网上百度了半天,终于让我找到了解决方案。在点击回复按钮时,加上如下代码既可解决无法获取编辑器内容:
$("#lnkbtnReply").click(function(){
var editor=$('#txtcontent').xheditor({tools:'simple',skin:'default'});
//alert($("#txtcontent").val());
editor.focus();
editor.setSource($("#txtcontent").val());
sHtml=editor.getSource();
});