我们如何获得HTML控件,如果任何放在RadEditor内

时间:2012-01-02 09:04:45

标签: asp.net telerik

我想了解如何在放置在RadEditor内并替换该值的情况下获取html控件。我试过这种方式来改变图像源。

 <script type="text/javascript">
function getEditor()
 {
    editor = $find("<%=reFormEditor.ClientID%>"); //return a reference to RadEditor
    var image = editor.get_document().body.document.getElementById("Image1");
}

这是我的aspx:

 <telerik:RadEditor runat="server" ID="reFormEditor">
<Content>
<asp:Button ID="btnSubmit2" runat="server" Text="Submit"/>
<img id="Image1" src="../Images/tabSelected.jpg" />
</Content>
</telerik:RadEditor>

我想在文本框keydown时更改图像源。帮助我解决这个问题。

1 个答案:

答案 0 :(得分:1)

这是代码,你不能把按钮放在内容中,它必须在编辑内容之外:

<body>
  <script type="text/javascript">
    function replaceImage() {
      var editor = $find("<%= reFormEditor.ClientID %>");
      var oDocument = editor.get_document()
      var img = oDocument.getElementById('imageInContents');
      img.src = '/image2.png';
    }  
  </script> 
  <form id="form1" runat="server">
    <asp:ScriptManager ID="mika" runat="server"></asp:ScriptManager>
    <telerik:RadEditor runat="server" ID="reFormEditor">
    <Content>
      <img id="imageInContents" src="/image1.png" />
    </Content>
    </telerik:RadEditor>
    <input type="button" onclick="replaceImage()" value="Replace Image" /> 
    </form>
</body>

以下是文字更改的示例

<body>
  <script type="text/javascript">
    function replaceSpanText() {
      var editor = $find("<%= reFormEditor.ClientID %>");
      var oDocument = editor.get_document()
      var spn = oDocument.getElementById('span1');
      spn.innerHTML = 'Text 2';
    }  
  </script> 
  <form id="form1" runat="server">
    <asp:ScriptManager ID="mika" runat="server"></asp:ScriptManager>
    <telerik:RadEditor runat="server" ID="reFormEditor">
    <Content>
      <span id="span1">Text 1</span>
    </Content>
    </telerik:RadEditor>
    <input type="button" onclick="replaceSpanText()" value="Replace text" /> 
    </form>
</body>