关于JavaScript中的select()与focus()

新建test.html页面代码如下:

<html>
<head>
<script type="text/javascript">
function selText()
  {
 // document.getElementById('password1').select()
  document.getElementById('password1').focus()
  }
script>
head>
<body>

<form>
<input type="password" id="password1" value="thgrt456" />
<input type="button" onclick="selText()" value="请添加内容" />
form>

body>
html>

运行结果如下图:
这里写图片描述
改为如下代码

<html>
<head>
<script type="text/javascript">
function selText()
  {
  document.getElementById('password1').select()
 // document.getElementById('password1').focus()
  }
script>
head>
<body>

<form>
<input type="password" id="password1" value="thgrt456" />
<input type="button" onclick="selText()" value="请添加内容" />
form>

body>
html>

运行结果为:这里写图片描述
从以上的图片很容易看出两者的区别。

你可能感兴趣的:(Java,javascript,java,web开发)