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

来源:互联网 发布:ubuntu上安装mysql 编辑:程序博客网 时间:2024/06/09 18:27

新建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>

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

原创粉丝点击