如何在<textarea>使用JavaScript中获得插入位置?
例如: This is| a text
这应该回来了7.
如何让它返回光标/选择周围的字符串?
例如:'This is', '', ' a text'.
如果突出显示"是"一词,那么它将返回'This ', 'is', ' a text'.
我正在使用JavaScript编辑textarea.问题是,当我在其中进行换行时,它们将不会显示.我怎样才能做到这一点?
我正在获得编写函数的值,但它不会给出换行符.
我已经开始看到一个AccessViolationException被我的应用程序抛出了几个不同的位置.它从未出现在我的开发PC上,我们的测试服务器上.它也仅在我们的2个生产服务器中的一个上显示出来.因为它似乎只发生在我们的一个生产服务器上,所以我开始在服务器上查看已安装的.net框架版本.
我发现(出于一些奇怪的原因),出现问题的生产服务器有2.0 sp2,3.0 sp2和3.5 sp1,而另一个生产服务器和测试服务器有2.0 sp1.
我的应用程序仅针对2.0框架,决定从生产服务器卸载所有框架版本并仅安装2.0 sp1.到目前为止,我还没有能够重现这个问题.很有意思.
开发pc:紧凑型2.0 sp2,紧凑型3.5,2.0 sp2,3.0 sp2,3.5 sp1测试服务器:2.0 sp1生产服务器1:2.0 sp1生产服务器2:2.0 sp2,3.0 sp2,3.5 sp1
现在,为什么我无法重现问题我的开发pc上有2.0 sp2,我想不出来.我听说有传言说这种访问违规可能发生在一些使用远程处理的软件上,我的确如此,但是当实际进行远程处理时,访问冲突永远不会发生.我现在只使用2.0 sp1,但我真的很想知道是否有人遇到过这个问题,如果他们找到了更新版本的frameowork的解决方法.
这里有几个例外和它们的堆栈跟踪:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at ICSharpCode.TextEditor.TextArea.HandleKeyPress(Char ch)
at ICSharpCode.TextEditor.TextArea.SimulateKeyPress(Char ch)
at ICSharpCode.TextEditor.TextArea.OnKeyPress(KeyPressEventArgs e)
at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
at System.Windows.Forms.Control.WmKeyChar(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
System.AccessViolationException: Attempted to read …Run Code Online (Sandbox Code Playgroud) 我想要的是计算textarea中的行数,例如:
line 1
line 2
line 3
line 4
Run Code Online (Sandbox Code Playgroud)
最多可以计4行.基本上按一次输入会转移到下一行
以下代码无效:
var text = $("#myTextArea").val();
var lines = text.split("\r");
var count = lines.length;
console.log(count);
Run Code Online (Sandbox Code Playgroud)
无论有多少行,它总是给出'1'.
我想找出并跟踪textarea中光标的"行号"(行).("更大的图片"是每次创建/修改/选择新行时解析行上的文本,如果当然没有粘贴文本.这样可以节省解析整个文本的时间间隔.)
StackOverflow上有几个帖子,但没有一个专门回答我的问题,大多数问题是光标位置(以像素为单位)或显示除textarea之外的行号.
我的尝试在下面,它从第1行开始并且不离开textarea时工作正常.单击textarea并在另一行上返回时,它会失败.将文本粘贴到其中时也会失败,因为起始行不是1.
我的JavaScript知识非常有限.
<html>
<head>
<title>DEVBug</title>
<script type="text/javascript">
var total_lines = 1; // total lines
var current_line = 1; // current line
var old_line_count;
// main editor function
function code(e) {
// declare some needed vars
var keypress_code = e.keyCode; // key press
var editor = document.getElementById('editor'); // the editor textarea
var source_code = editor.value; // contents of the editor
// work out how many lines we have used in total
var lines = source_code.split("\n");
var total_lines = lines.length; …Run Code Online (Sandbox Code Playgroud) 我已经为房地产经纪人管理做了一个c#申请.
在那个应用程序中,我有一个mdi表单,其中包含所有菜单.
在我选择代理主服务器的菜单中,一个表单附带添加代理按钮.
单击"添加代理"按钮时,将打开"另一个窗口",其中包含要填充的代理详细信
当我关闭此表格时,我的问题是>>
"Attempt to read or write protected memory.This often an indication that other memory is corrupt"
Run Code Online (Sandbox Code Playgroud)
错误来了.当我在此应用程序的消息框上单击确定时,整个应用程序将关闭.
当我通常通过visual studio运行应用程序时,此错误不会发生.
但是,当我运行代码的exe时,会出现此错误.
这个错误有什么解决方案吗?
我在发布或调试项目时犯了错误吗?
我的堆栈跟踪:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& …Run Code Online (Sandbox Code Playgroud) javascript ×4
textarea ×3
.net ×2
c# ×2
caret ×1
cursor ×1
html ×1
jquery ×1
line-breaks ×1
servicepacks ×1