将ComboBox值插入AJAX HTML编辑器 [英] Inserting ComboBox values into AJAX HTML editor

查看:121
本文介绍了将ComboBox值插入AJAX HTML编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试将ComboBox值插入Ajax Html编辑器时,我遇到了很多问题。我在这里看到了一些相关的问题,我已经尝试了几个列为已接受答案的脚本,但我仍然无法获取要插入的值。我使用的是Visual Studio 2010,它是一个ASP.Net WebApp。我不能为我的生活理解为什么它不会插入价值观,当人们显然没有问题时。我试图从ComboBox插入值,以作为将在以后插入的数据库值的占位符。我会在这里发布我的代码,我真的很感激任何人可以提供的任何帮助或建议。



我尝试了几种不同的脚本试图让这个工作正常,但没有一个产生任何结果。我能够得到的最远的是其中一个脚本似乎刷新了SelectedIndex Changed事件的页面,并擦除了编辑器中存在的任何内容。这根本没有用,我无法理解为什么会这样做。



 <   asp:ComboBox     ID   =  ComboBox1    runat   =  server >  
< asp:ListItem = %meternumberFieldHolder% > Meter Number < / asp:ListItem >
< asp:ListItem = %accountnumberFieldHolder% > 帐号< / asp:ListItem >
< / asp:ComboBox >

< br / >

< cc1:编辑 ID = Editor1 runat = server 高度 = 500px / >

& nbsp; < 脚本 类型 = text / javascript >
$(文件)。ready( function (){
$(' #<%:ComboBox1.ClientID%>')。change( function (){
var cbtext = $(' < span class =code-string>#<%:ComboBox1.ClientID%>选项:选择了)文本();
var cbtext = ' [' + ddltext + ' ]'
InsertAtCursor(Editor1,cbtext); // 插入功能
});
});

function InsertAtCursor(myField,myValue){

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

else if (myField.selectionStart == < span class =code-digit> 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 。长度);
}
else {
myField.value + = myValue;
}
}
< / script >





改编自我在这里找到的答案 http://stackoverflow.com/questions/10509707/insert-text-at-cursor-position-in-ajax-html-editor-using-client-script/10554972#10554972 [<一个href =http://stackoverflow.com/questions/10509707/insert-text-at-cursor-position-in-ajax-html-editor-using-client-script/10554972#10554972\"target =_ blanktitle = 新窗口> ^ ]

那里的人似乎没有任何问题,但我无法让它工作。

解决方案

document )。ready( function (){

' #<%:ComboBox1.ClientID%>')。change( function (){
var cbtext =


' #<%:ComboBox1.ClientID%>选项:选择了)文本();
var cbtext = ' [' + ddltext + ' ]'
InsertAtCursor(Editor1,cbtext); // 插入功能
});
});

function InsertAtCursor(myField,myValue){

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

else if (myField.selectionStart == < span class =code-digit> 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 。长度);
}
else {
myField.value + = myValue;
}
}
< / script >





改编自我在这里找到的答案 http://stackoverflow.com/questions/10509707/insert-text-at-cursor-position-in-ajax-html-editor-using-client-script/10554972#10554972 [<一个href =http://stackoverflow.com/questions/10509707/insert-text-at-cursor-position-in-ajax-html-editor-using-client-script/10554972#10554972\"target =_ blanktitle = 新窗口> ^ ]

那里的人似乎没有任何问题,但我无法让它工作。


I have been having a lot of issues as I try to insert ComboBox values into the Ajax Html editor. I have seen a few questions on here related, and I've tried several of the scripts that are listed as accepted answers, but I still cannot get the values to insert at all. I am using Visual Studio 2010, and it is an ASP.Net WebApp. I cannot for the life of me understand why it will not insert the values, when people obviously have no issues with it. I am trying to insert values from the ComboBox to act as placeholders for Database Values that will be inserted at a later time. I'll post my code here, and I would really appreciate any help or advice anyone can offer.

I have tried several different scripts in an attempt to get this working, but none have yielded any results. The furthest I was able to get was one of the scripts appeared to refresh the page on the SelectedIndex Changed event, and wipe any content that existed in the editor. That wasn't at all helpful, and I could not understand why it even did that.

<asp:ComboBox ID="ComboBox1" runat="server">
    <asp:ListItem Value="%meternumberFieldHolder%">Meter Number</asp:ListItem>
    <asp:ListItem Value="%accountnumberFieldHolder%">Account Number</asp:ListItem>
</asp:ComboBox>

        <br />

        <cc1:Editor ID="Editor1" runat="server" Height="500px" />

        &nbsp;<script type="text/javascript">
            $(document).ready(function () {
                $('#<%:ComboBox1.ClientID%>').change(function () {
                    var cbtext = $('#<%:ComboBox1.ClientID%> option:selected').text();
                    var cbtext = ' [' + ddltext + '] '
                    InsertAtCursor(Editor1, cbtext); //Function for Insertion
                });
            });

            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;
                }
            }
        </script>



This is adapted from an answer I found here http://stackoverflow.com/questions/10509707/insert-text-at-cursor-position-in-ajax-html-editor-using-client-script/10554972#10554972[^]
And people there seem to have no issues with this, but I cannot get it to work.

解决方案

(document).ready(function () {


('#<%:ComboBox1.ClientID%>').change(function () { var cbtext =


('#<%:ComboBox1.ClientID%> option:selected').text(); var cbtext = ' [' + ddltext + '] ' InsertAtCursor(Editor1, cbtext); //Function for Insertion }); }); 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; } } </script>



This is adapted from an answer I found here http://stackoverflow.com/questions/10509707/insert-text-at-cursor-position-in-ajax-html-editor-using-client-script/10554972#10554972[^]
And people there seem to have no issues with this, but I cannot get it to work.


这篇关于将ComboBox值插入AJAX HTML编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆