-
為了舉例簡單明了,我就直接使用文本編輯器程序演示方法,大家也可以使用其他編輯軟件,還可以直接利用系統中自帶的記事本來編輯。
-
首先輸入網頁基本的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" onclick="getfocus()" value="獲得焦點">
<input type="button" onclick="losefocus()" value="失去焦點">
-
將代碼保存為html格式,預覽下效果。
-