<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="布尔教育 http://www.itbool.com" />
<script>
function toggle() {
//window指定对象tese1赋值给变量test1
var test1 = document.getElementById("test1");
//检索src中,第一次出现on.gif检索on返回0执行off.gif,第二次检索返回-1执行else
if (test1.src.indexOf("on") >= 0) {
test1.src = "off.gif";
}else{
test1.src = "on.gif";
}
}
</script>
</head>
<body>
//鼠标点击触动toggle() 执行script中 function toggle()
<img id = "test1" src = "on.gif" alt = "" onclick = "toggle();">
</body>
</html>
js特效-开关灯泡
最新推荐文章于 2022-12-07 20:13:48 发布