此代码将用户在框中键入的内容更改为大写,并在框中显示结果。
<html>
<head>
<script type="text/javascript">
function upperCase(x)
{
var y=document.getElementById(x).value;
document.getElementById(x).value=y.toUpperCase();
document.getElementById("mySpan").value=y.toUpperCase();
}
</script>
</head>
<body>
Enter your name: <input type="text" id="fname" onkeyup="upperCase(this.id)">
<br/>
<span id="mySpan"></span>
</body> </html>
但是我怎样才能让它显示在文本框下面呢?以及当用户键入时,大写文本显示在文本框下方?
谢谢!
最佳答案
我会建议以下更易于维护的方法,它使用 event registration model而不是 inline model :
JS:
<script>
document.getElementById("fname").onkeyup = function() {
document.getElementById("mySpan").innerHTML = this.value.toUpperCase();
}
</script>
标记:
Enter your name: <input type="text" id="fname"/>
<br/>
<span id="mySpan"></span>
关于javascript - HTML 表单文本 onkeyup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4362291/