用Ajax编辑器控件asp dot net改变标签的字体样式

时间:2016-06-04 23:26:25

标签: javascript c# asp.net ajaxcontroltoolkit

我的页面上有以下asp控件

  1. 标签
  2. 带有ajax编辑器控件的文本框
  3. 我有javascript检查textbox ajax编辑器控件的keyup事件并将值赋给label。但奇怪的是,它没有将字体颜色,文本框大小分配给标签。

    这是脚本和htmll

       <script type="text/javascript">
         Sys.Application.add_load(function () {
             var htmlEditorBox = $('.ajax__html_editor_extender_texteditor');
             htmlEditorBox.keyup(function () {
                 document.getElementById('<%=Label2.ClientID%>').innerHTML = this.textContent;
                <%-- document.getElementById('<%=Label2.ClientID%>').style.color = this.textColor.innerHTML;--%>
    
             });
         });
    </script>
    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
    <asp:TextBox ID="TextBox1" runat="server" Width="300" Height="200">     </asp:TextBox>
    <ajaxToolkit:HtmlEditorExtender runat="server" BehaviorID="TextBox1_HtmlEditorExtender" TargetControlID="TextBox1" ID="TextBox1_HtmlEditorExtender" EnableSanitization="False"></ajaxToolkit:HtmlEditorExtender>
    

    我想将textbox ajax控件编辑器格式设置为标签

2 个答案:

答案 0 :(得分:0)

尝试将以下代码放在keyup事件中。我已经完成了它并且工作得很好:

var color = $(this).css('color');
var fontSize = $(this).css('font-size');

alert(color + "," + fontSize);

document.getElementById('<%=Label1.ClientID%>').style.color = color;
document.getElementById('<%=Label1.ClientID%>').style.fontSize = fontSize;

答案 1 :(得分:0)

我得到了答案

<div>
<script type="text/javascript">
    Sys.Application.add_load(function () {
        var htmlEditorBox = $('.ajax__html_editor_extender_texteditor');
        htmlEditorBox.keyup(function () {
            document.getElementById('lblContents').innerHTML = $('.ajax__html_editor_extender_texteditor').html();
        });
    });
</script>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:TextBox ID="txtEditor" CssClass="Editor" runat="server" Width="300" Height="200" />
<asp:HtmlEditorExtender ID="HtmlEditorExtender1" runat="server"          TargetControlID="txtEditor"
    EnableSanitization="false">
</asp:HtmlEditorExtender>
<br />
<asp:Button ID="Button1" Text="Submit" runat="server" />
<br />
Entered Text:
<asp:Label ID="lblContents" runat="server" />
</div>