| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 521 人关注过本帖
标题:初学者,请各位好心精英耐心回答,十二万分谢谢!谢谢!!
只看楼主 加入收藏
漫颜
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2012-12-12
结帖率:50%
收藏
 问题点数:0 回复次数:4 
初学者,请各位好心精英耐心回答,十二万分谢谢!谢谢!!
不好意思,问题有点多,可能会占用您一些时间,都是自己学习,实在是不太懂。网上的教程,代码都是自己抄下了写的,希望耐心的好心人能解答下,顺便给些指点。万分感谢了!

1
,函数:将脚本编写为函数,就可以避免载入时执行该脚本————载入时肯定要执行函数,怎么会避免执行呢??
函数包含一些代码,这些代码只有在函数被调用时,或只能被事件激活时才能执行————如果javascripta在外部,那么函数会在它调用时才生效,至于调用,那么
function func(){
document.write("hello world");}
func():————函数的执行,有了它就可以调用。。调用是这个意思吗?
直接写document.write("hello world");就可以有的效果,写在函数里到底有什么好处呢?

2
<html>
<head>
<title>
arguments对象
</title>
</head>
<ul>
<li id="xhtml">xhtml</li>
<li id="css">css</li>
<li id="java">java</li>
</ul>
<script type="text/javascript" language="javascript">
//<![CDATA[
window['jauery']={};
window['jauery']['$']=$;
function $(){
var elements=[];
for(var i=0;i<arguments.length;i++){
element=arguments[i];
if{typeof element=="string";{
element=document.getElementById(element);}
if(argements.length==1){//为什么这样写呢?arguements“数组”长度等于1,这里是3呢,不是不能返回值了吗?
return element;}
elements.push(element);}
return elements}
var items=jauery.$("xhtml","css","java");
for(i=0;i<items.length;i++){
items[i].style.color="red";
}
//]]>
</script>
</body>
</html>
这段代码不能实现效果,哪里错了呢?

3,<html>
<head>
<title>
函数的递归
</title>
</head>
<body>
<script language="javascript" type="text/javascript">
//<!CDATA[[
function sayhello1(){
document.write("sayhello5");}
sayhello1();
function sayhello2(){
return "hello"}
document.write(sayhello2());
//为什么这样写不可以呢?
/*for(var i=result=1;i<=5;i++){
result=result*i};
ducument.write(result);*/
function func1(){
for(var i=result=1;i<=n;i++){
result=result*i;}
return result};
document.write(func1(5));
//哪里错了呢,为什么不能实现5的阶乘呢?
//]]>
</script>
</body>
</html>


4,<html>
<head>
<title>
回调函数
</title>
</head>
<body>
<script language="javascript" type="text/javascript">
//<!CDATA[[
var color=[];
color[0]=[0,0,0];
color[1]=[255,255,255];
color[2]=[100,100,100];
color[3]=[255,0,0];
color[4]=[0,255,0];
color[5]=[0,0,255];
color[6]=[0,255,255];
color[7]=[255,255,0];
color[8]=[255,0,255];
color[9]=[-125,255,255];
color[10]=[233,123];
window.onload=function(){
document.body.style.background="rgb("+color[7]+")"
}
function checkcolor(element){
return(element?=0&&<=255);}
function checkcount(index){
return index.length==3}
for(var i in color){
document.write(color[i].filter(checkcolor,checkcount)+"<br/>")}
//哪里有错呢??
//]]>
</script>
</body>
</html>

最后一个,谢谢了!!
<html>
<head>
<title>
函数的闭包
</title>
</head>
<body>
<script language="javascript" type="text/javascript">
//<!CDATA[[
var sml="hello world";
function sayhello(){
alert(sml)}
sayhello();
var ib=10;
function add(iNum1,iNum2){
function ad(){
return iNum1+iNum2+ib}
}
return ad();}
alert(add(1,2));
function countnum()num{
return function(toadd){
return num+toadd;}}
var result=countnum(5);
alert(result(5));
//这两段函数哪里有问题呢??
//]]>
</script>
</body>
</html>


谢谢每一位回帖者,新年快乐。也祝愿论坛里的人们年年都有不一样的喜欢的满足的收获。




搜索更多相关主题的帖子: function 
2013-01-08 20:32
芥末小弟
Rank: 2
来 自:北京
等 级:论坛游民
帖 子:58
专家分:92
注 册:2013-1-19
收藏
得分:0 
1,函数:将脚本编写为函数,就可以避免载入时执行该脚本,当进行相关的调用时候,才会去执行。
func():————函数的执行,有了它直接在方法的事件的方法名就能调用。
直接写document.write("hello world");就可以有的效果,写在函数里可以封装一些通用的脚本验证。提高代码的重用性。

开发者。。
QQ:690591637
2013-01-19 19:55
芥末小弟
Rank: 2
来 自:北京
等 级:论坛游民
帖 子:58
专家分:92
注 册:2013-1-19
收藏
得分:0 
为什么这样写呢?arguements“数组”长度等于1,这里如果是3,就不会执行这个if下的语句。

开发者。。
QQ:690591637
2013-01-19 19:56
fysk12
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-1-25
收藏
得分:0 
这个要非常的细心!!

上海立体画http://www.ufa.so
2013-01-25 09:56
鱼忻铭
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-8-29
收藏
得分:0 
function func1(){
for(var i=result=1;i<=n;i++){
result=result*i;}
return result};
document.write(func1(5));//哪里错了呢,为什么不能实现5的阶乘呢?
这样写就可以了啊
function func(n)
{
    for(var i=result=1;i<=n;i++)
    {
        result=result*i;
    }
        return result;
}
document.write(func(5));
2013-03-28 09:55
快速回复:初学者,请各位好心精英耐心回答,十二万分谢谢!谢谢!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020413 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved