趴着睡觉肚子胀气:帅哥,靓女帮我看一下代码错在哪了!谢谢

来源:百度文库 编辑:高校问答 时间:2024/03/28 19:13:54
打扰了!
你们有什么好的学习方法吗?说详细点!
我现在是一个人在看javascript书自学!
有好的学习方法告诉我可以吗?拿来共享下哦!
请你们先帮我检查一下下面的代码,我不知道什么地方错了,无法正常显示!
<script>
document.title="改变背景颜色";
var url= new Array(3);
url[0]="http://www.baidu.com";
url[1]="http://www.szpc.net";
url[2]="http://www.meijing.com";

function mOver(cell){
cell.bgcolor="red";
cell.style.cursor="hand";
}
function mOut(cell){
cell.bgcolor="blue";
}
function goto(i){
location=ulr[i];
}
</script>
我最喜欢的网站:
<table>
<tr>
<td onMouseOver="mOver(this)" onMouseOver="mOut(this)"
onClick="goto(0)"><li>百度

<td onMouseOver="mOver(this)" onMouseOver="mOut(this)"
onClick="goto(1)"><li>网上书签

<td onMouseOver="mOver(this)" onMouseOver="mOut(this)"
onClick="goto(2)"><li>梦境
</tr>
</table>

其中的"this"是不是指目前对象mOver的意思?
<td onMouseOver="mOver(this)" onMouseOver="mOut(this)"
加不加有什么区别?
什么时候要加?

cell.bgcolor=...
改成
cell.style.background=...

location=ulr[i];
改成
location=url[i];

this是一个对象,具体是什么是要看调用它的对象.你可以用下面的代码看出来:
function mOut(cell){
cell.bgcolor="blue";
alert(cell);//如果在调用它的对象上加个ID,alert(cell.id)就更好看懂了
}

至于那个bgcolor为什么不能改变...从我测试的情况看,他好像是个改变什么的属性,你可以在函数体内加alert(cell.bgcolor)语句得到它的颜色值(注:如果没定义则返回undefined),但我在网上搜索的结果却是没有什么教材或文章提到它的存在...看来我得再重新学了.
楼主说到学JS的方法,多练,多看,多写,不怕错,不怕问,不怕烦

下面是我修改过的代码;应该符合你的要求;
Java 脚本是分大小写的,如果你写的属性,变量有一个字母不一样也就不一样的,大小字.

<script>
document.title="改变背景颜色";
var url= new Array(3);
url[0]="http://www.baidu.com";
url[1]="http://www.szpc.net";
url[2]="http://www.meijing.com";

function mOver(cell){

cell.bgColor="red";
cell.style.cursor="hand";
}

function mOut(cell){

cell.bgColor="blue";
}

function goto(i){

location=url[i];

}

</script>
我最喜欢的网站:
<table>
<tr>
<td id="baidu" onMouseOver="mOver(this)" onMouseOut="mOut(this)"
onClick="goto(0)"><li>百度

<td id="shu" onMouseOver="mOver(this)" onMouseOut="mOut(this)"
onClick="goto(1)"><li>网上书签

<td id="mengjing" onMouseOver="mOver(this)" onMouseOut="mOut(this)"
onClick="goto(2)"><li>梦境
</tr>
</table>