日期:2014-05-17  浏览次数:20545 次

HTML DOM select() 方法

定义和用法

select() 方法用于选取密码域中的文本。
语法
passwordObject.select()
实例

下面的例子可选取密码域中的文本:
<html>
<head>
<script type="text/javascript">
function selText()
? {
? document.getElementById('password1').select()
? }
</script>
</head>
<body>

<form>
<input type="password" id="password1" value="thgrt456" />
<input type="button" onclick="selText()" value="Select text" />
</form>

</body>
</html>

参考:http://www.w3school.com.cn/htmldom/met_password_select.asp

?

?

实战用法:当用户没有输入密码、密码格式错误的时候,给出提示

if(document.forms[0].password.value==null || document.forms[0].password.value==""){
??alert("提示:请输入密码。");
??document.forms[0].password.select();
??return false;
?}