我想在用户写入时将文本框中的文本转换为大写。
HTML/aspx:
<asp:TextBox runat="server" ID="mytextbox" onkeydown="toUpperCase()"></asp:TextBox>
jQuery
function toUpperCase() {
$(this.val) = this.val.toUpperCase();
}
最佳答案
使用下面的代码来满足您的要求。我们提供了在按下键和按下键时更改大写字母的所有代码。为此,您可以使用 html 和 Asp 控件。
function toUpperCase(ctrl) {
$(ctrl).val($(ctrl).val().toUpperCase());
}
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<table>
<tr>
<td>Enter value to change per character:-</td><td><input type="text" id="txt1" onkeyup="toUpperCase(this);" /></td>
</tr>
<tr>
<td>Enter value to change previous character:- </td><td><input type="text" id="txt2" onkeydown="toUpperCase(this);" /></td>
</tr>
</table>
</body>
</html>
关于javascript - Asp.net 使用 jQuery 将文本框输入转换为大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44393232/