html失去获得焦点

it2025-04-09  9

 

 

 

 

为了举例简单明了,我就直接使用文本编辑器程序演示方法,大家也可以使用其他编辑软件,还可以直接利用系统中自带的记事本来编辑。

 

首先输入网页基本的html代码。

<html>

   <body>

   </body>

</html>

 

然后,在<html>后面添加<head>代码.

<head></head>

并在标签之间为超链接添加样式代码

<style type="text/css">

    a:active {color:green}

</style>

 

下面在<script>标签中定义两个函数,输入代码:

  <script type="text/javascript">

    function getfocus()

     {document.getElementById('jingyan').focus()}

  </script>

这个函数作用是获得焦点。

 

然后再输入定义失去焦点的函数。

    function losefocus()

     {document.getElementById('jingyan').blur()}

 

点击正文<body>标签后,定义一个文字链接:

<a id="jingyan" href="http://jingyan.baidu.com">点击访问百度经验</a>

 

然后在下面添加两个按钮,用来执行获得和失去焦点。

 

<input type="button" οnclick="getfocus()" value="获得焦点">

<input type="button" οnclick="losefocus()" value="失去焦点">

 

将代码保存为html格式,预览下效果。

 

转载于:https://www.cnblogs.com/lhlong/p/11168767.html

最新回复(0)