javascript 为何不能执行?

来源:百度知道 编辑:UC知道 时间:2024/06/11 15:04:03
<!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=gb2312" />
<title>无标题文档</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.x {
background-color: #000000;
}
-->
#s1 {
height: 30px;
width: 998px;
background-image: url(index1.jpg);
background-repeat: no-repeat;
}
#s2 {
height: 30px;
width: 998px;
background-image: url(inde

代码中的
<script language="javascript">
document.getElementById('s1').style.display='none';
document.getElementById('s2').style.display='block';
</script>

这段,需要放到 div s1 和 s2 的后面,

因为只有页面加载了2个div ,s1和 s2 后,你再使用document.getElementById('s1') 才能获得该div

你放到了 2个 div 的代码之前,这个时候,document.getElementById('s1') 是获取不到相应的div,所以代码是无法执行的

此外代码中 此处的 onMousemove 好像没什么用的吧!

<div id="zhu" onMousemove="xs('s2');xx('s1');">

修改后代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www