新建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>
运行结果为:
从以上的图片很容易看出两者的区别。