在文本区域中的文本中显示用户选择的文本

Display the User selected text in Text in Text area

本文关键字:文本 选择 用户 显示 区域      更新时间:2023-09-26
<script type="text/javascript">
        /* run on document load **/
        function disp() {
            //var text = document.getElementById('TextArea1').value;
            var text = document.getElementById('MainContent_TextArea1').value;
            //alert('a')
            if (text == null)
            {
                return false;
            } 
            else
            {
                var t = text;
          var t = text.substr(text.selectionStart, text.selectionEnd -text.selectionStart);
               document.getElementById('displayval').value = t;
                 alert(t)
                }
            }
  </script>
    <div>
    <input id="TextArea1" runat="server" type="text"/>
    <INPUT type="button" onclick= "disp()" visible="true" value="Show"/>
    <INPUT type="text"  id ="displayval" visible="true" />
    </div>

在这里,我尝试通过警报显示用户选择的文本。但我想在 Textarea2 到 C# 中显示此数据。如何在 C# 中调用此函数。请帮忙。

尝试:

$('#text-area2-id').val(t);

这将在文本区域 2 中显示它,而不是警报。


如何在 C# 中调用此函数?你不能。Javascript在客户端运行,在服务器将所有内容发送到客户端之后。

您可以使用以下命令调用 JavaScript 函数代码

Page.ClientScript.RegisterStartupScript(this.GetType((,"CallMyFunction","MyFunction((",true(;