资源预览内容
第1页 / 共8页
第2页 / 共8页
第3页 / 共8页
第4页 / 共8页
第5页 / 共8页
第6页 / 共8页
第7页 / 共8页
第8页 / 共8页
亲,该文档总共8页全部预览完了,如果喜欢就下载吧!
资源描述
Javascript总结(代码篇)1)Alert boxfunction disp_alert()alert(I am an alert box!)(2) confirm boxfunction disp_confirm() var r=confirm(Press a button) if (r=true) document.write(You pressed OK!) else document.write(You pressed Cancel!) (3)Prompt boxfunction disp_prompt() var name=prompt(Please enter your name,Harry Potter) if (name!=null & name!=) document.write(Hello + name + ! How are you today?) (4) Call a function1function myfunction()alert(HELLO)By pressing the button, a function will be called. The function will alert a message.(5)Function with an argumentfunction myfunction(txt)alert(txt)By pressing the button, a function with an argument will be called. The function will alertthis argument.(7)Function with an argument 2function myfunction(txt)alert(txt)When you click on one of the buttons, a function will be called. The function will alertthe argument that is passed to it.(8)Function_returnfunction myFunction()return (Hello, have a nice day!)document.write(myFunction()The script in the body section calls a function.The function returns a text.(9)function product(a,b)return a*bdocument.write(product(4,3)The script in the body section calls a function with two parameters (4 and 3).The function will return the product of these two parameters.(10)forfor (i = 0; i = 5; i+)document.write(The number is + i)document.write()Explanation:This for loop starts with i=0.As long as i is less than, or equal to 5, the loop will continue to run.i will increase by 1 each time the loop runs.(11)for (i = 1; i = 6; i+)document.write(This is header + i)document.write()(12)whilei = 0while (i = 5)document.write(The number is + i)document.write()i+Explanation:i is equal to 0.While i is less than , or equal to, 5, the loop will continue to run.i will increase by 1 each time the loop runs.(13)do.whilei = 0dodocument.write(The number is + i)document.write()i+while (i = 5)Explanation:i equal to 0.The loop will runi will increase by 1 each time the loop runs.While i is less than , or equal to, 5, the loop will continue to run.(14)breakvar i=0for (i=0;i=10;i+)if (i=3)breakdocument.write(The number is + i)document.write()Explanation: The loop will break when i=3.(15)try.catchvar txt=function message()try adddlert(Welcome guest!) catch(err) txt=There was an error on this page.nn txt+=Error description: + err.description + nn txt+=Click OK to continue.nn alert(txt)
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号