利用JavaScript实现文本框改文字功能
<html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script> function settext(){ var otext=document.getElementById('text1'); otext.value='123'; } </script> </head> <body> <input id="text1" type="text" value="abc" /> <input type="button" value="改文字" onClick="settext()" /> </body> </html>
另一种方法:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
输入:<input type="text" id="myInput" oninput="myFunction()" onclick="locationInput">
显示:<input id="demo" type="text" value="" />
<script type="text/javascript">
window.onload = function () {
locationInput = function () {
};
}
</script>
<script>
function myFunction() {
var x = document.getElementById("myInput").value;
document.getElementById("demo").value = x;
}
</script>
</body>
</html>
欢迎访问每天进步网:https://meitianjinbu.cn/

浙公网安备 33010602011771号