我有一个关于asp.net小写到大写的问题以及如何为此编写java脚本 [英] i have a question on asp.net lower case to upper case and how to write java script for that
本文介绍了我有一个关于asp.net小写到大写的问题以及如何为此编写java脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的JAVASCRIPT
THIS IS MY JAVASCRIPT
<script language="javascript" type="text/javascript">
function ToUpper(id) {
document.getElementById(id).value = document.getElementById(id).value.toUpperCase();
}
</script>
我的问题是我输入总名称,如果我在中间输入另一个文本,它将变为大写
这封信的名字来自最后一个
例子
首次输入的名字
abc xyz
my problem is i enter total name and it will change to uppercase
if i enter another text in middle of name the letter is showed from last
example
first entered name
abc xyz
after i want to change name in mddle like bellow
abc defxyz
<pre lang="sql">if enter any two letters after one letter the blinking cursor go to last of name and loke bellow
abc d xyzef
怎么解决你能告诉我
how to solve can you tell me
推荐答案
问题是编辑文本输入值作为某人类型会将插入符号(光标)位置重置为新文本之后。
你需要A :在更改文本之前到达插入符号位置; B:在更改文本后设置插入符号:
The issue is that editing the text inputs value as someone types will reset the caret (cursor) position to after the new text.
You need to A: Get where the caret is before changing the text and B: Set the caret after changing the text:
function A(element){
//You will won't to add some error checking here - such as if(!element.selection) return 0;
return element.selectionStart;
}
function B(element, caret){
//Selecting a range with the same start and end will place the caret at that point
element.setSelectionRange(caret,caret);
}
//just pass the element instead of id
function toUpper(element){
var caret = A(this);
this.value = this.value.ToUpperCase();
B(this,caret);
}
哦,并传递整个元素(你不必去):
Oh and pass the whole element (you don't HAVE to though):
<asp:textbox id="txtPatientname" runat="server" onkeyup="ToUpper(this)" cssclass="txtbox" font-names="Calibri" font-size="Medium" height="20px" maxlength="50" tabindex="6" tooltip="Patient name" width="175px" xmlns:asp="#unknown"></asp:textbox>
希望有所帮助:)
Hope that helps :)
这篇关于我有一个关于asp.net小写到大写的问题以及如何为此编写java脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文