插入文本在阿贾克斯的HTML编辑器中的光标位置,使用客户端脚本光标、脚本、客户端、器中

2023-09-10 13:56:10 作者:葬之心海

我有一个Ajax的HTML编辑器,它上面的下拉。 在选择一个项目形成我想在下拉列表中所选项目的文本,以获得在AJAX的HTML编辑器的当前光标位置粘贴的下拉列表。 任何想法..?

I have an Ajax HTML editor and a Dropdown above it. On choosing an item form the Dropdown I want the Text of the selected item in the Dropdown to get pasted at the current cursor position in the AJAX HTML editor. Any ideas..?

推荐答案

是的第3天,我终于得到了我的问题的解决方案的结束,它张贴在这里,这样的人可以节省有precious时间由重-inventing轮。

Yeah at the end of the Third day I finally got a solution for my problem, posting it here so that someone can save there precious time from re-inventing the wheel.

这是我的Ajax ATML编辑:

This is my Ajax ATML Editor:

<Ajax:Editor ID="EdtrHTML" runat="server" />

我想从下拉列表中选中的文本,在HTML编辑器的当前光标位置粘贴,所以我打电话的功能,插入的下拉的改变事件的文本(InsertAtCursor)。

I want the selected text from the dropdown to be pasted at the current cursor position in the HTML editor,so I'm calling the function to insert text(InsertAtCursor) on the "change" event of the dropdown.

作为参数传递给函数InsertAtCursor我传递这被创建在渲染HTML编辑器iframe的ID。

As a parameter to the function InsertAtCursor i'm passing the ID of the IFrame which gets created while rendering HTML editor.

 $(document).ready(function () {
            $('#<%:DropDownID.ClientID%>').change(function () {
            var ddltext = $('#<%:DropDownID.ClientID%> option:selected').text();
            var ddltext = ' [' + ddltext + '] '
            InsertAtCursor(idofHTMLEditorIFrame, ddltext);//Function for Insertion
        });
    });

这是插入从下拉文本在阿贾克斯的HTML编辑器的光标位置的功能。

This is the function which inserts Text from the dropdown at the cursor position of Ajax HTML Editor.

 function InsertAtCursor(myField, myValue) {

        if (document.selection) {
            myField.focus();
            sel = document.selection.createRange();
            sel.text = myValue;
        }

        else if (myField.selectionStart == 0 || myField.selectionStart == '0') {
            var startPos = myField.selectionStart;
            var endPos = myField.selectionEnd;
            myField.value = myField.value.substring(0, startPos) + myValue +
                        myField.value.substring(endPos, myField.value.length);
        }
        else {
             myField.value += myValue;
        }
    } 

在我的情况下,我的Ajax编辑器是内部的更新面板等后部分回发的脚本停止工作,而且我发现帮助here.

In my case my Ajax Editor was inside an Update panel and so after a partial post back the script stopped working, and i found help here.

希望这对你的作品太...干杯.. !!

Hope this works for you too...Cheers..!!