将ComboBox值插入AJAX HTML编辑器

编程入门 行业动态 更新时间:2024-10-16 16:24:32
本文介绍了将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 = $(' #<%: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 == 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 >

改编自我在这里找到的答案 stackoverflow/questions/10509707/insert-text-at-cursor-position-in-ajax-html-editor-using-client-script/10554972#10554972 [ ^ ] 那里的人似乎没有任何问题,但我无法让它工作。

解决方案

( 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 == 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 >

改编自我在这里找到的答案 stackoverflow/questions/10509707/insert-text-at-cursor-position-in-ajax-html-editor-using-client-script/10554972#10554972 [ ^ ] 那里的人似乎没有任何问题,但我无法让它工作。

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 stackoverflow/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 stackoverflow/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编辑器

本文发布于:2023-11-25 00:34:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627581.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编辑器   ComboBox   AJAX   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!