本文实例讲述了js实现文本框选中的方法。分享给大家供大家参考。具体如下:

这段javascript代码可解决文本框获得焦点,即使得文本框的内容被选中。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>select文件</title>
<script language="javascript" type="text/javascript">
function getFocus()
{
  document.getElementById("test").select();
}
</script>
</head>
<body>
<form id="f1">
<input type="text" id="test" name="test" value="你好嗎?" 
onfocus="getFocus();"/>
</form>
</body>
</html>

希望本文所述对大家的javascript程序设计有所帮助。

点赞(138)

评论列表共有 0 条评论

立即
投稿
返回
顶部