Add JavaScript to HTML

HTML এ জাভাস্ক্রিপ্ট যোগ করুন

নিম্নলিখিত তিনটি উপায় রয়েছে যার মাধ্যমে আমরা HTML নথিতে জাভাস্ক্রিপ্ট কোড যোগ করতে পারি:

জাভাস্ক্রিপ্ট কোডটি … ট্যাগে অন্তর্ভুক্ত করুন।

… ট্যাগ এবং বডি ট্যাগ বন্ধ হওয়ার পরে জাভাস্ক্রিপ্ট কোড অন্তর্ভুক্ত করুন।

HTML এ জাভাস্ক্রিপ্টের আলাদা ফাইল লিঙ্ক করুন

জাভাস্ক্রিপ্ট কোড ট্যাগে অন্তর্ভুক্ত করুন।

এই বিভাগে, আপনি এবং ট্যাগের মধ্যে জাভাস্ক্রিপ্ট কোড অন্তর্ভুক্ত করতে শিখবেন।

বাক্য গঠন

  1. html>  
  2. head>  
  3. script>  
  4. JavaScript Code  
  5. Statement 1  
  6. Statement 2  
  7. ……  
  8. Statement N  
  9. script>  
  10. head>  
  11. body>  
  12. body>  
  13. html>  

উপরের সিনট্যাক্সে, ট্যাগ রাখা হয়।

উদাহরণ

  1. >  
  2. html>  
  3. head>  
  4. meta name=“viewport" content=“width=device-width, initial-scale=1">  
  5. title>  
  6. Include JavaScript in head tag   
  7. title>  
  8. <script>  
  9. function check()  
  10. {  
  11. /* The following statement is used to display a Confirm dialog box on a webpage with the statement which is enclosed in the brackets. */  
  12. confirm(“Your JavaScript Code Run");   
  13. }  
  14. script>  
  15. <style>  
  16. /* The following tag selector button use the different properties for the Button. */  
  17. button {  
  18.   background-color: red;  
  19. padding: 16px 20px;  
  20.   margin: 8px 0;  
  21.   border: none;  
  22.   cursor: pointer;  
  23.   color: white;  
  24.   width: 100%;  
  25.   opacity: 0.9;  
  26. }  
  27. /* The following tag selector hover use the opacity property for the Button which select button when you mouse over it. */  
  28. button:hover {  
  29. opacity: 1;  
  30. }  
  31. style>  
  32. head>  
  33. <body>  
  34. <form>  
  35.   
  36. <button type=“button" onclick=“check()"> Click Me for running a JavaScript Code button>   
  37. form>  
  38. body>  
  39. html>   

2. i) ট্যাগে জাভাস্ক্রিপ্ট কোড অন্তর্ভুক্ত করুন।

এই বিভাগে, আপনি এবং ট্যাগের মধ্যে জাভাস্ক্রিপ্ট কোড কীভাবে অন্তর্ভুক্ত করবেন সে সম্পর্কে শিখবেন।

বাক্য গঠন

  1. <html>  
  2. <head>  
  3. head>  
  4. <body>  
  5.   
  6. <script>  
  7. JavaScript Code  
  8. Statement 1  
  9. Statement 2  
  10. ……  
  11. Statement N  
  12. script>  
  13. body>  
  14. html>  

উপরের সিনট্যাক্সে, ট্যাগটি HTML ফাইলে এবং ট্যাগের মধ্যে রাখা হয়।

উদাহরণ

  1. >  
  2. <html>  
  3. <head>  
  4. <meta name=“viewport" content=“width=device-width, initial-scale=1">  
  5. <title>  
  6. Include JavaScript in body tag   
  7. title>  
  8. <style>  
  9. /* The following tag selector button use the different properties for the Button. */  
  10. button {  
  11.   background-color: red;  
  12.    padding: 16px 20px;  
  13.   margin: 8px 0;  
  14.   border: none;  
  15.   cursor: pointer;  
  16.  color: white;  
  17.   width: 100%;  
  18.   opacity: 0.9;  
  19. }  
  20. /* The following tag selector hover use the opacity property for the Button which select button when you mouse over it. */  
  21. button:hover {  
  22. opacity: 1;  
  23. }  
  24. style>  
  25. head>  
  26. <body>  
  27. <form>  
  28. <script>  
  29. function bdy_JS ()  
  30. {  
  31. /* The following statement is used to display a Confirm dialog box on a webpage with the statement which is enclosed in the brackets. */  
  32. confirm(“Your JavaScript Code Run which is used in the Body tag");  
  33. }  
  34. script>  
  35.   
  36.   
  37. <button type=“button" onclick=“bdy_JS()"> Click Me for running a JavaScript Code button>  
  38. form>  
  39. body>  
  40. html>

ii) ট্যাগের পরে জাভাস্ক্রিপ্ট কোড অন্তর্ভুক্ত করুন।

এই বিভাগে, আপনি ট্যাগের পরে JavaScript কোড অন্তর্ভুক্ত করতে শিখবেন।

বাক্য গঠন

  1. <html>  
  2. <head>  
  3. head>  
  4. <body>  
  5. body>  
  6. <script>  
  7. JavaScript Code  
  8. Statement 1  
  9. Statement 2  
  10. ……  
  11. Statement N  
  12. script>   
  13. html>  

উপরের সিনট্যাক্সে, ট্যাগ বসানো হয়।

উদাহরণ:

  1. >  
  2. <html>  
  3. <head>  
  4. <meta name=“viewport" content=“width=device-width, initial-scale=1">  
  5. <title>  
  6. Include JavaScript code after the body tag   
  7. title>  
  8. <style>  
  9. /* The following tag selector button use the different properties for the Button. */  
  10. button {  
  11.   background-color: red;  
  12.   color: white;  
  13.   margin: 8px 0;  
  14.   border: none;  
  15.   cursor: pointer;  
  16.   width: 100%;  
  17.   padding: 16px 20px;  
  18.   opacity: 0.9;  
  19. }  
  20. /* The following tag selector hover use the opacity property for the Button which select button when you mouse over it. */  
  21. button:hover {  
  22. opacity: 1;  
  23. }  
  24. style>  
  25. head>  
  26. <body>  
  27. <form>  
  28.   
  29. <button type=“button" onclick=“bdy_JS()"> Click Me for running a JavaScript Code button>  
  30.   
  31. form>  
  32. body>  
  33. <script>  
  34. function bdy_JS ()  
  35. {  
  36. /* The following statement is used to display a Confirm dialog box on a webpage with the statement which is enclosed in the brackets. */  
  37. confirm(“Your JavaScript Code Run which is used after the Body tag");  
  38. }  
  39. script>  
  40. html>  

HTML এ জাভাস্ক্রিপ্টের আলাদা ফাইল লিঙ্ক করুন

এই বিভাগে, আপনি HTML ফাইলে JavaScript কোডের ফাইল অন্তর্ভুক্ত করতে শিখবেন।

বাক্য গঠন

  1. <html>  
  2. <head>  
  3. <script src="Name_of_JavaScript_file>  
  4. script>  
  5. head>  
  6. <body>  
  7. body>  
  8. html>  

উপরের সিনট্যাক্সে, src হল