从WYSIWYG文本编辑器获取格式化文本后按钮没有触发,同时在信息文本中工作正常

时间:2015-04-09 09:16:46

标签: javascript jquery asp.net twitter-bootstrap wysiwyg

我正在使用JYSery和Bootstrap的WYSIWYG文本编辑器。当我尝试在按钮单击时获取未格式化的文本时,它可以正常工作,但是当尝试获取格式化文本时,它甚至不会在服务器端触发。

function customEditor() 
{
  $("#tbNewsEditor").Editor();
}

来自编辑器的onclient click事件getText并保存在隐藏字段中此函数中没有异常。

 function NewsEditorText() 
    {
      try
      {
        var newsEditorText = $("#tbNewsEditor").Editor("getText");

        alert(newsEditorText);

        document.getElementById('<%=hfNewsEditorText.ClientID %>').value =    
        newsEditorText;

        alert(document.getElementById('<%=hfNewsEditorText.ClientID %>').value);

      }
      catch (e) 
      {

      }
         return true;   
      }

        <div class="row">
           <div class="col-md-12">
                <asp:TextBox ID="tbNewsEditor" runat="server"></asp:TextBox>
            </div>
            <div class="col-md-12">
                 <asp:HiddenField ID="hfNewsEditorText" runat="server" />
                 <asp:Button ID="btnNewsEditor" runat="server" Text="Button" 
                  OnClientClick="return NewsEditorText()"  
                  OnClick="btnNewsEditor_Click"/>
            </div>
          </div>

         protected void btnNewsEditor_Click(object sender, EventArgs e) 
                {
                    try
                    {
                        string newsEditorText = hfNewsEditorText.Value;
                    }
                    catch (Exception ex)
                    {

                    }
                }

页面加载调用成功加载编辑器的Javascript函数customEditor。

protected void Page_Load(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "customEditor", "customEditor();", true);

            if (!IsPostBack)
            {

               //TODO 
            }
        }

我无法弄清楚它在无格式文本中的工作正常,而在格式化文本按钮的情况下不会触发。我正在获取简单的文本但是在格式化文本(html)按钮的情况下不会触发。

0 个答案:

没有答案