JavaScript Programming Fundamentals
Document Details
Uploaded by Deleted User
Taif University
Dr. Hesham Kamal, Dr. Many بنت ماجد اليامي
Tags
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 =