在使用ajax时,xheditor编辑器中的文本框无法获取内容的解决方案

前段时间,利用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();

});

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值