JavaScript Programming Fundamentals

Document Details

Uploaded by Deleted User

Taif University

Dr. Hesham Kamal, Dr. Many بنت ماجد اليامي

Tags

javascript programming web development coding programming languages

Summary

This document contains lecture notes for a course on JavaScript programming. The notes cover topics such as the introduction to JavaScript, basic JavaScript in HTML, how to use JavaScript in HTML, how to deal with old browsers that do not support JavaScript, variables and operators, conditional statements and loops. The documents also contain examples of how to use JavaScript. The course is offered at Taif University.

Full Transcript

‫ﻣﻘﺮر ﺗﻄ()ﺮ ﺗﻄﺒ‪+‬ﻘﺎت اﻻﺟﻬﺰة اﻟﺬﻛ‪+‬ﺔ‬ ‫رﻗﻢ اﻟﻤﻘﺮر ‪3-66034103‬‬ ‫ﻗﺴﻢ ﻧﻈﻢ اﻟﻤﻌﻠﻮﻣﺎت اﻹدار;ﺔ‬ ‫=ﻠ>ﺔ إدارة اﻷﻋﻤﺎل‬ ‫إﻋﺪاد‪:‬‬ ‫د‪.‬ﻫﺸﺎم =ﻤﺎل ﻋﺮﻓﺎت‬ ‫د‪.‬ﻣ‪ IJ‬ﺑ‪L‬ﺖ ﻣﺎﺟﺪ اﻟ>ﺎ‪PQ‬‬ ‫‪1‬‬ ‫اﻟﻮﺣﺪة اﻟﺮا)ﻌﺔ‬ ‫‪...

‫ﻣﻘﺮر ﺗﻄ()ﺮ ﺗﻄﺒ‪+‬ﻘﺎت اﻻﺟﻬﺰة اﻟﺬﻛ‪+‬ﺔ‬ ‫رﻗﻢ اﻟﻤﻘﺮر ‪3-66034103‬‬ ‫ﻗﺴﻢ ﻧﻈﻢ اﻟﻤﻌﻠﻮﻣﺎت اﻹدار;ﺔ‬ ‫=ﻠ>ﺔ إدارة اﻷﻋﻤﺎل‬ ‫إﻋﺪاد‪:‬‬ ‫د‪.‬ﻫﺸﺎم =ﻤﺎل ﻋﺮﻓﺎت‬ ‫د‪.‬ﻣ‪ IJ‬ﺑ‪L‬ﺖ ﻣﺎﺟﺪ اﻟ>ﺎ‪PQ‬‬ ‫‪1‬‬ ‫اﻟﻮﺣﺪة اﻟﺮا)ﻌﺔ‬ ‫‪JavaScript‬‬ ‫‪2‬‬ ‫أﻫﺪاف اﻟﻮﺣﺪة اﻟﺮا‪,‬ﻌﺔ‪JavaScript :‬‬ ‫‪A‬‬ ‫اﻟﻔﺼﻞ اﻷول‪ :‬ﻣﻘﺪﻣﺔ ﻋﻦ ﻟﻐﺔ ‪JavaScript‬‬ ‫اﻟﻔﺼﻞ اﻟﺜﺎ ‪ :TB‬اﺳﺎﺳ‪V‬ﺎت ﻟﻐﺔ ‪ JavaScript‬داﺧﻞ ﺻﻔﺤﺔ ‪HTML‬‬ ‫ ﻛ‪O‬ﻒ ﻳﺘﻢ وﺿﻊ ﻛﻮد ‪ JavaScript‬داﺧﻞ ﺻﻔﺤﺔ ‪HTML‬‬ ‫‪JavaScript $‬‬ ‫ ﻣﺎ ‪%‬‬ ‫ ﻛ‪O‬ﻔ‪O‬ﺔ اﻟﺘﻌﺎﻣﻞ ﻣﻊ اﻟﻤﺘﺼﻔﺤﺎت اﻟﻘﺪ‪x‬ﻤﺔ اﻟ ‪ y% z‬ﻻ ﺗﺪﻋﻢ ‪JavaScript‬‬ ‫‪ $‬ﻧﻔﺴﻬﺎ ‪Java‬؟‬ ‫ ﻫﻞ ﻟﻐﺔ اﻟ‪56‬ﻣﺠﺔ ‪% JavaScript‬‬ ‫ اﻳﻦ ﻳﺘﻢ وﺿﻊ ﻛﻮد ‪ JavaScript‬داﺧﻞ ﺻﻔﺤﺔ ‪HTML‬‬ ‫ ﻣﺎ اﻟﺬي ?ﺴﺘﻄﻴﻊ ﺻﻨﻌﻪ ﻟﻐﺔ ‪JavaScript‬؟‬ ‫|‬ ‫ ﺗﻨﻔ‪O‬ﺬ ﻛﻮد ‪ {% JavaScript‬اﻟﺼﻔﺤﺔ‬ ‫ ﻣﻌﻠﻮﻣﺎت ﺗﺎر‪M‬ﺨ‪O‬ﺔ ﻋﻦ ‪JavaScript‬‬ ‫‪A‬‬ ‫‪A‬‬ ‫اﻟﻔﺼﻞ اﻟﺮاﺑﻊ‪ :‬اﻟﻤﺘﻐ_^ات واﻟﻌﻮاﻣﻞ ‪ @B‬ﻟﻐﺔ ‪JavaScript‬‬ ‫اﻟﻔﺼﻞ اﻟﺜﺎﻟﺚ‪ :‬اﻟﺠﻤﻞ ‪ @B‬ﻟﻐﺔ ‪JavaScript‬‬ ‫; ﻗ=ﻤﻬﺎ‪.‬‬‫ اﻟﻤﺘﻐ'&ات ‪ -‬ﻗﻮاﻋﺪ ‪/‬ﺴﻤﻴﺘﻬﺎ – اﻹﻋﻼن ﻋﻨﻬﺎ– ﺗﻌﻴ ' ﻘﺔ أن =ﻞ ﻟﻐﺔ ﻣﺨﺘﻠﻔﺔ ﻋﻦ اﻷﺧﺮى ﺗﻤﺎﻣﺎ ﻣﻦ ﺣ>ﺚ اﻟﻤﻔﻬﻮم واﻟﺘﺼﻤ>ﻢ‪.‬‬ ‫‪ e‬ﻟﻐﺔ ﻗ‪;v‬ﺔ وأ ‚‪ Yƒ‬ﺗﻌﻘ>ﺪا ﻣﻦ ﻟﻐﺔ اﻟ‪YZ‬ﻣﺠﺔ‬ ‫‪x‬‬ ‫‪t‬‬ ‫ ﻟﻐﺔ اﻟ‪YZ‬ﻣﺠﺔ ‪ Java‬و اﻟ ‪ IQ‬ﻗﺎﻣﺖ ﺑﺘﻄ‪;v‬ﺮﻫﺎ ‪w‬ﻛﺔ ‪Q Sun Microsystems‬‬ ‫‪J‬‬ ‫‪ JavaScript‬و ‪R‬ﻤﻜﻦ ﻣﻘﺎرﻧﺘﻬﺎ …ﻠﻐﺎت اﻟ‪YZ‬ﻣﺠﺔ اﻷﺧﺮى ‪ †Q‬ﻧﻔﺲ اﻟﻔﺌﺔ ﻣﺜﻞ ‪ C‬و ‪C++‬‬ ‫‪J‬‬ ‫‪ Œ‬ﺴ>ﻄﺔ و ‪Ž‬ﺴﺘﺨﺪم =ﻤﺎ أ‪wx‬ﻧﺎ ﺳﺎ…ﻘﺎ ‪ †Q‬إﺿﺎﻓﺔ اﻟﺘﻔﺎﻋﻞ إ‘ ﺻﻔﺤﺎت ‪HTML‬‬ ‫ أﻣﺎ ﻟﻐﺔ ‪ JavaScript‬ﻓ ‪Q‬‬ ‫‪6‬‬ ‫ﻣﺎ اﻟﺬي ‪O‬ﺴﺘﻄﻴﻊ ﺻﻨﻌﻪ ﻟﻐﺔ ‪JavaScript‬؟‬ ‫‪ n‬ﺻﻔﺤﺎت اﻟـ ‪p HTML‬ﺄداة ﺳﻬﻠﺔ ﻟﻠ‪^t‬ﻣﺠﺔ‪:‬‬ ‫‪.1‬ﺗﺰو‪S‬ﺪ ﻣﺼﻤ ‪B‬‬ ‫ﻋﺎدة ﻣﺎ ‪x‬ﻜﻮن أﺻﺤﺎب ﺻﻔﺤﺎت اﻟ¡‪M‬ﺐ ﻟ§ﺴﻮا ﻣﻦ اﻟﻤ‪6 5‬ﻣﺠ‪³ ،| ²‬وﻟ‪W‬ـﻦ ﻧﻈـﺮا ﻟ‪W‬ـﻮن ﻟﻐـﺔ ﺟﺎﻓﺎﺳـﻜˆ‪‰M‬ﺖ ﻟﻐـﺔ ﺑﺮﻣﺠـﺔ ذات ﺟﻤـﻞ ‪Ž‬ﺴـ‪O‬ﻄﺔ ﺟـﺪا· ‪x‬ﻤﻜـﻦ‬ ‫ﺗﻘˆ‪¤M‬ﺎ ﻷي ﺷﺨﺺ وﺿﻊ أﺟﺰاء ﻛﻮد ﺟﺎﻓﺎﺳﻜˆ‪‰M‬ﺖ | ‪ {%‬ﺻﻔﺤﺎت ‪ HTML‬اﻟﺨﺎﺻﺔ ﺑﻬﻢ‪.‬‬ ‫‪A‬‬ ‫‪.2‬وﺿﻊ ﻧﺼﻮص دﻳﻨﺎﻣ‪V‬ﻜ‪V‬ﺔ ‪ @B‬ﺻﻔﺤﺎت ‪:HTML‬‬ ‫)">‪document.write("" + name + "ﺎﺳ>ﺔ ﻟﻠﻐﺔ ‪ ECMAScript‬واﻟ‪ It‬ﺗﻢ ﺗﻄ‪;v‬ﺮﻫﺎ ﺑﻮاﺳﻄﺔ ﻣﻨﻈﻤﺔ‬ ‫ ﺟﺎﻓﺎﺳﻜ–;—ﺖ ‪Q‬‬ ‫‪.(European Computer Manufacturers Association) ECMA‬‬ ‫‪J‬‬ ‫ ﺗﻢ اﺧ‪Yt‬اع ﻟﻐﺔ ﺟﺎﻓﺎﺳﻜ–;—ﺖ أول ﻣﺮة ﺑﻮاﺳﻄﺔ ‪ Netscape †Q Brendan Eich‬و=ﺎﻧﺖ ﻣﺪﻣﺠﺔ ﻣﻊ اﻟﻤﺘﺼﻔﺢ‬ ‫‪ Navigator 2.0‬وﺗﻢ ﺗﻐﻴ©‪ Y‬اﺳﻤﻬﺎ ﻣﻦ ‪ Mocha‬إ‘ ‪.LiveScript‬‬ ‫ ﺛﻢ أﺧ©‪Y‬ا ﺗﻐ©‪ Y‬اﺳﻤﻬﺎ إ‘ ‪… JavaScript‬ﻌﺪ اﻻﺗﻔﺎق ﺑ © ‪J‬‬ ‫‪ Netscape -‬و ‪ sun Microsystems‬وأﺻ‪T‬ﺤﺖ‬ ‫¯‬ ‫‪J‬‬ ‫ﻣﻮﺟﻮدة ‪ †Q‬ﺟﻤﻴﻊ اﻟﻤﺘﺼﻔﺤﺎت …ﺪءا ﻣﻦ ﻋﺎم ‪.1996‬‬ ‫‪9‬‬ ‫‪O‬‬ ‫اﻟﻔﺼﻞ اﻟﺜﺎ ‪ :NP‬اﺳﺎﺳ‪Q‬ﺎت ﻟﻐﺔ ﺟﺎﻓﺎﺳﻜ@‪BA‬ﺖ‬ ‫‪JavaScript Language basics‬‬ ‫اﻟﻌﻮدة ﻻﻫﺪاف اﻟﻮﺣﺪة‬ ‫‪10‬‬ ‫ﻛ‪+‬ﻒ ﻳﺘﻢ وﺿﻊ ﻛﻮد ﺟﺎﻓﺎﺳﻜ‪g)f‬ﺖ داﺧﻞ ﺻﻔﺤﺔ‬ ‫‪HTML‬‬ ‫>‪‪‪ "‪‪document.write("This is a paragraph.ﺺ(‪.‬‬ ‫ﻋﻨﺪ اﻟﻘ>ﻢ اﻟﻨﺼ>ﺔ ﺗﻮﺿﻊ ﺑ © ‪J‬‬ ‫‪23‬‬ ‫‪v‬‬ ‫اﻟﻌﻮاﻣﻞ ‪ u9 Operators‬ﺟﺎﻓﺎﺳﻜ‪g)f‬ﺖ‬ ‫‪4‬‬ ‫ﺗﺪﺧﻞ اﻟﻌﻮاﻣﻞ ‪ 35 Operators‬إ‪7‬ﺸﺎء اﻟﺘﻌﺒ>=ات اﻟﺤﺴﺎﺑ‪C‬ﺔ و اﻟﻤﻨﻄﻘ‪C‬ﺔ وﺗﻘﺪم ﺟﺎﻓﺎﺳﻜ‪QPO‬ﺖ أﻧﻮاع ﻛﺜ>=ة ﻣﻦ اﻟﻌﻮاﻣﻞ ﻣﻨﻬﺎ اﻟﻌﻮاﻣﻞ اﻟﺤﺴﺎﺑ‪C‬ﺔ و‬ ‫_‪.‬‬ ‫^‬ ‫اﻟﻌﻮاﻣﻞ اﻟﻤﻨﻄﻘ‪C‬ﺔ و ﻋﻮاﻣﻞ اﻟﻤﻘﺎرﻧﺔ واﻟﻌﺎﻣﻞ اﻟ] ‪5‬‬ ‫‪w‬‬ ‫ ‪a‬ﺴﺘﺨﺪم اﻟﻌﻮاﻣﻞ اﻟﺤﺴﺎﺑ‪C‬ﺔ ﻹﺟﺮاء ﻋﻤﻠ‪C‬ﺎت ﺣﺴﺎﺑ‪C‬ﺔ ﻋ‪ g‬ﻣﺘﻐ>=ات أو ﻗ‪C‬ﻢ ﺛﺎﺑﺘﺔ )ﻋﺎﻣﻞ اﻟﺠﻤﻊ ‪ +‬و اﻟﻄ‪O‬ح ‪ -‬و اﻟ‪r4‬ب * و اﻟﻘﺴﻤﺔ ‪ /‬و اﻟ‪v‬ﺎ ‪٪ 35‬‬ ‫وﻋﺎﻣﻞ اﻟ‪Py‬ﺎدة ‪ ++‬وﻋﺎﻣﻞ اﻟﻨﻘﺼﺎن ‪(--‬‬ ‫ ‪ true‬أو ‪ ،( False‬ﻣﺜﻞ ﻋﺎﻣﻞ اﻟ„ﺴﺎوي == و ﻋﺎﻣﻞ ﻋﺪم اﻟ„ﺴﺎوي >< و‬ ‫ ‪a‬ﺴﺘﺨﺪم ﻋﻮاﻣﻞ اﻟﻤﻘﺎرﻧﺔ ﻟﻤﻘﺎرﻧﺔ اﻟﻘ‪C‬ﻢ اﻟﻤﻨﻄﻘ‪C‬ﺔ )و~ اﺣﺪ ﻗ‪C‬ﻤﺘ > ‪4‬‬ ‫‪5‬‬ ‫ﻋﺎﻣﻞ اﻗﻞ ﻣﻦ أو ‪‰‬ﺴﺎوي =< و ﻋﺎﻣﻞ ا‪ =‹Š‬ﻣﻦ أو ‪‰‬ﺴﺎوي => و ﻋﺎﻣﻞ أ ‪ =‹Š‬ﻣﻦ > و ﻋﺎﻣﻞ أﻗﻞ ﻣﻦ ‪4‬‬ ‫‘ﻼ ﻣﻌﺎﻣﻠ‪C‬ﻪ ‪ true‬و || واﻟﺬي ‪Ž‬ﻌ‪C‬ﺪ اﻟﻘ‪C‬ﻤﺔ ‪ false‬ﻓﻘﻂ اذا ‘ﺎن ‘ﻼ ﻣﻌﺎﻣﻠ‪C‬ﻪ ‪ false‬أﻣﺎ ! ﻓ‪C‬ﻌﻜﺲ ﻗ‪C‬ﻤﺔ ﻣﻌﺎﻣﻠﻪ ﻣﻦ ‪ true‬ا‪ false ˜5‬واﻟﻌﻜﺲ‬ ‫ ™ﺤ‪C‬ﺚ ﺗﻜﻮن اﻟﻘ‪C‬ﻤﺔ اﻟﺮاﺟﻌﺔ ~ اﻟﻘ‪C‬ﻤﺔ اﻻو˜ إذا ﺗﺤﻘﻖ اﻟ^]ط أو اﻟﻘ‪C‬ﻤﺔ اﻟﺜﺎﻧ‪C‬ﺔ إذا ﻟﻢ ﻳﺘﺤﻘﻖ اﻟ^]ط‪،‬‬ ‫ اﻟﻌﺎﻣﻞ اﻟ^]_ ‪Ž‬ﻌ‪C‬ﺪ ﻗ‪C‬ﻤﺔ ﻣﻦ ﺑ > ‪4‬‬ ‫ ﻗ‪C‬ﻤﺘ > ‪4‬‬ ‫‪5‬‬ ‫اﻟﺸ‪Ÿ‬ﻞ اﻟﻌﺎم ﻟﻬﺎ‪:‬‬ ‫‪(condition) ? value1 : value2‬‬ ‫اﻟﺠﺪول اﻟﺘﺎ‪ ˜5‬ﻳﻮﺿﺢ ™ﻌﺾ اﻷﻣﺜﻠﺔ ﻟﻬﺬە اﻟﻌﻮاﻣﻞ‪.‬‬ ‫‪24‬‬ ‫اﻟﻌﻮاﻣﻞ‬ ‫ﻧﻮﻋﻬﺎ‬ ‫اﻟﻮﻇ‪V‬ﻔﺔ‬ ‫ﻣﺜﺎل‬ ‫اﻟﻨﺎﺗﺞ‬ ‫‪++‬‬ ‫ﺣﺴﺎﺑ‪6‬ﺔ‬ ‫ز‪2‬ﺎدة ﻗ‪6‬ﻤﺔ اﻟﻤﺘﻐ8‬ﺎﻓ‪+,‬اض ‪x=5‬‬ ‫‪false‬‬ ‫=

Use Quizgecko on...
Browser
Browser